home *** CD-ROM | disk | FTP | other *** search
/ Revista do CD-ROM 101 / CD-ROM 101.iso / compl / maya5ple / Install_MayaPLE5_English.exe / Maya / Data1.cab / hyperShadePanel.mel < prev    next >
Encoding:
Text File  |  2003-07-17  |  176.0 KB  |  7,087 lines

  1. // Copyright (C) 1997-2002 Alias|Wavefront,
  2. // a division of Silicon Graphics Limited.
  3. //
  4. // The information in this file is provided for the exclusive use of the
  5. // licensees of Alias|Wavefront.  Such users have the right to use, modify,
  6. // and incorporate this code into other products for purposes authorized
  7. // by the Alias|Wavefront license agreement, without fee.
  8. //
  9. // ALIAS|WAVEFRONT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
  10. // INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
  11. // EVENT SHALL ALIAS|WAVEFRONT BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  12. // CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
  13. // DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  14. // TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  15. // PERFORMANCE OF THIS SOFTWARE.
  16. //
  17. //
  18. //  Creation Date:  December 8/2000
  19. //  Author:         jdc rendering
  20. //
  21. // Description:
  22. //
  23. //        This file contains the procedures which create and manipulate the
  24. //        Hypershade panel UI.
  25. //                                                
  26.  
  27. global int $gRenderCreateBarIconsOnlyWidth = 65;
  28. global int $gRenderCreateBarIconsAndTextMinWidth = 160;
  29. global int $gRenderCreateBarIconsAndTextMaxWidth = 360;
  30.  
  31. if (`about -os` == "nt")
  32. {
  33.     $gRenderCreateBarIconsOnlyWidth = 60;
  34.     $gRenderCreateBarIconsAndTextMinWidth = 163;
  35. }
  36.  
  37. if(`about -mac`){
  38.     $gRenderCreateBarIconsOnlyWidth = 100;
  39.     $gRenderCreateBarIconsAndTextMinWidth = 163;
  40. }
  41.  
  42. // This script is sourced at startup by initScriptedPanels.mel. We will take
  43. // this opportunity to ensure that the option vars related to node creation (ie
  44. // with/without placement, as normal/projection/stencil...) exist.
  45. //
  46. initCreateNodeOptionVars();
  47.  
  48. // Initialize the optionVar which specifies which tab sections are to be shown,
  49. // if it does not already exist.
  50. //
  51. if (!`optionVar -exists hyperShadePanelTabSectionsShown`)
  52. {
  53.     optionVar 
  54.         -stringValue 
  55.             hyperShadePanelTabSectionsShown 
  56.             "showTopAndBottomTabs";
  57. }
  58.  
  59. // Initialize the optionVar which specifies whether the create bar is to be 
  60. // shown, if the optionVar does not already exist.
  61. //
  62. if (!`optionVar -exists hyperShadePanelCreateBarShown`)
  63. {
  64.     optionVar -intValue hyperShadePanelCreateBarShown true;
  65. }
  66.  
  67. // Initialize the optionVar which specified how wide the create bar should be
  68. // when in icons and text mode, if the optionVar does not already exist.
  69. //
  70. if (!`optionVar -exists hyperShadePanelCreateBarIconsAndTextWidth`)
  71. {
  72.     global int $gRenderCreateBarIconsAndTextMinWidth;
  73.  
  74.     optionVar 
  75.         -intValue 
  76.             hyperShadePanelCreateBarIconsAndTextWidth
  77.             $gRenderCreateBarIconsAndTextMinWidth;
  78. }
  79.  
  80. // Initialize the optionVar which specifies whether to clear before graphing,
  81. // if it does not already exist.
  82. //
  83. if (!`optionVar -exists hsClearBeforeGraphing`)
  84. {
  85.     optionVar -intValue hsClearBeforeGraphing true;
  86. }
  87.  
  88. if (!`scriptedPanelType -exists hyperShadePanel`) 
  89. //
  90. // If you change this, you must also change the one in 
  91. // initScriptedPanels.mel
  92. //
  93. {
  94.     //
  95.     //  Define the callbacks for the shader editor panel.
  96.     //
  97.     scriptedPanelType
  98.         -createCallback        "createHyperShadePanel" 
  99.         -initCallback        "initHyperShadePanel"
  100.         -addCallback        "addHyperShadePanel"
  101.         -removeCallback        "removeHyperShadePanel"
  102.         -saveStateCallback    "saveStateHyperShadePanel"
  103.         -deleteCallback        "deleteHyperShadePanel"
  104.         -unique true
  105.         hyperShadePanel;
  106.  
  107. }
  108.  
  109. proc string hyperShadePanelName()
  110. //
  111. // Description:
  112. //    This procedure returns the name of the panel containing the 
  113. //    shader editor.
  114. //    If there is no shader editor in existence, the behaviour of this
  115. //    procedure is undefined.
  116. //
  117. //    ASSUMPTION: This procedure assumes there is a maximum of one 
  118. //    shader editor open. 
  119. //
  120. {
  121.     string $hyperShadePanels[] = 
  122.         `getPanel -scriptType "hyperShadePanel"`;
  123.     
  124.     return $hyperShadePanels[0];
  125. }
  126.  
  127. // ---------------------------------------------------------------------------
  128. //     Registry to record tabs and their associated libraryUI, graphUI and
  129. //     collectionUI components.
  130. // 
  131.  
  132. global string $gHyperShadePanelLookupTable[];
  133. global int $gHyperShadePanelLookupTableCreated = false;
  134.  
  135. proc createHyperShadePanelLookupTable()
  136. {
  137.     //
  138.     // Description:
  139.     //    This procedure initializes the string array
  140.     //    $gHyperShadePanelLookupTable[] for use as a lookup table. The lookup
  141.     //    table will contain information about the tabs of the hypershade panel,
  142.     //    and the UI contained within them.
  143.     //
  144.  
  145.     global string $gHyperShadePanelLookupTable[];
  146.     global int $gHyperShadePanelLookupTableCreated;
  147.  
  148.     if (!$gHyperShadePanelLookupTableCreated)
  149.     {
  150.         string $columns[];
  151.  
  152.         $columns[0] = "tab";
  153.         $columns[1] = "type";
  154.         $columns[2] = "componentName";
  155.         $columns[3] = "optionVar";
  156.  
  157.         lookupTable($gHyperShadePanelLookupTable, $columns);
  158.         $gHyperShadePanelLookupTableCreated = true;
  159.     }
  160. }
  161.  
  162. proc registerTab(
  163.     string $tab,
  164.     string $type,
  165.     string $libraryUI,
  166.     string $optionVar)
  167. {
  168.     //
  169.     // Description:
  170.     //    This procedure enters information about the specified tab into the
  171.     //    lookup table that contains information about all of the tabs in the
  172.     //    hypershade panel.
  173.     //
  174.  
  175.     if (    ($type != "disk") 
  176.         &&     ($type != "graph") 
  177.         &&     ($type != "protected graph") 
  178.         &&     ($type != "scene"))
  179.     {
  180.         error
  181.             -showLineNumber true
  182.             ("Attempted to register unrecognized tab type.");
  183.     }
  184.  
  185.     global string $gHyperShadePanelLookupTable[];
  186.     string $row[];
  187.  
  188.     $row[0] = $tab;
  189.     $row[1] = $type;
  190.     $row[2] = $libraryUI;
  191.     $row[3] = $optionVar;
  192.  
  193.     lookupTableAddRow($gHyperShadePanelLookupTable, $row);
  194. }
  195.  
  196. proc unregisterTab(
  197.     string $tab)
  198. {
  199.     //
  200.     // Description:
  201.     //    This procedure removes information about the specified tab from the
  202.     //    lookup table.
  203.     //
  204.  
  205.     global string $gHyperShadePanelLookupTable[];
  206.  
  207.     lookupTableRemoveRow(
  208.         $gHyperShadePanelLookupTable,
  209.         "tab",
  210.         $tab);
  211. }
  212.  
  213. proc string lookupComponentName(
  214.     string $tab)
  215. {
  216.     //
  217.     // Description:
  218.     //    This procedure uses the lookup table to look up the name of the
  219.     //    UI component (ie libraryUI, collectionUI or graphUI) associated with 
  220.     //     the specified tab.
  221.     //
  222.     // Returns: 
  223.     //    The name of the UI component associated with the specified tab.
  224.     //
  225.  
  226.     global string $gHyperShadePanelLookupTable[];
  227.  
  228.     return lookupTableLookup(
  229.         $gHyperShadePanelLookupTable,
  230.         "tab",
  231.         $tab,
  232.         "componentName");
  233. }
  234.  
  235. proc string lookupTabOptionVar(
  236.     string $tab)
  237. {
  238.     //
  239.     // Description:
  240.     //    This procedure uses the lookup table to look up the name of the
  241.     //    optionVar which stores information about the specified tab. The
  242.     //    information stored in these optionVars is used to recreate tabs with
  243.     //    the same characteristics in subsequent Maya sessions, and also to
  244.     //    recreate tabs when the panel is torn off into a window.
  245.     //
  246.     // Returns: 
  247.     //    The name of the optionVar associated with the specified tab.
  248.     //
  249.  
  250.     global string $gHyperShadePanelLookupTable[];
  251.  
  252.     return lookupTableLookup(
  253.         $gHyperShadePanelLookupTable,
  254.         "tab",
  255.         $tab,
  256.         "optionVar");
  257. }
  258.  
  259. proc string lookupOptionVarTab(
  260.     string $optionVar)
  261. {
  262.     //
  263.     // Description:
  264.     //    This procedure uses the lookup table to look up the name of the tab
  265.     //    associated with the specified optionVar.
  266.     //
  267.     // Returns: 
  268.     //    The name of the tab associated with the specified optionVar.
  269.     //
  270.  
  271.     global string $gHyperShadePanelLookupTable[];
  272.  
  273.     return lookupTableLookup(
  274.         $gHyperShadePanelLookupTable,
  275.         "optionVar",
  276.         $optionVar,
  277.         "tab");
  278. }
  279.  
  280. proc string lookupTabType(
  281.     string $tab)
  282. {
  283.     //
  284.     // Description:
  285.     //    This procedure uses the lookup table to look up the type (disk, scene,
  286.     //    graph, protected graph) of the specified tab.
  287.     //
  288.     // Returns: 
  289.     //    The type of the specified tab.
  290.     //
  291.  
  292.     global string $gHyperShadePanelLookupTable[];
  293.  
  294.     return lookupTableLookup(
  295.         $gHyperShadePanelLookupTable,
  296.         "tab",
  297.         $tab,
  298.         "type");
  299. }
  300.  
  301. proc int isDiskTab(
  302.     string $tab)
  303. {
  304.     //
  305.     // Description:
  306.     //    This procedure is used to query whether the specified tab is a disk
  307.     //    tab.
  308.     //
  309.     // Returns: 
  310.     //    True if the tab is a disk tab, false if not.
  311.     //
  312.  
  313.     global string $gHyperShadePanelLookupTable[];
  314.  
  315.     return (lookupTabType($tab) == "disk");
  316. }
  317.  
  318. proc int isGraphTab(
  319.     string $tab)
  320. {
  321.     //
  322.     // Description:
  323.     //    This procedure is used to query whether the specified tab is a graph
  324.     //    tab.
  325.     //
  326.     // Returns: 
  327.     //    True if the tab is a graph tab or protected graph tab, false if not.
  328.     //
  329.  
  330.     global string $gHyperShadePanelLookupTable[];
  331.  
  332.     string $type = lookupTabType($tab);
  333.  
  334.     return (($type == "graph") || ($type == "protected graph"));
  335. }
  336.  
  337. proc int isSceneTab(
  338.     string $tab)
  339. {
  340.     //
  341.     // Description:
  342.     //    This procedure is used to query whether the specified tab is a scene
  343.     //    tab.
  344.     //
  345.     // Returns: 
  346.     //    True if the tab is a scene tab, false if not.
  347.     //
  348.  
  349.     global string $gHyperShadePanelLookupTable[];
  350.  
  351.     return (lookupTabType($tab) == "scene");
  352. }
  353.  
  354. // ---------------------------------------------------------------------------
  355. //     Procedures to find out information about the current tab
  356. // 
  357. proc int activePaneIndex(
  358.     string $panel)
  359. {
  360.     //
  361.     // Description:
  362.     //    This procedure determines what pane within the hypershade panel is the
  363.     //    active pane.
  364.     //
  365.     // Returns: 
  366.     //    The index of the active pane within the paneLayout called
  367.     //    paneArrangement.
  368.     //
  369.  
  370.     setParent $panel;
  371.     string $paneLayout = `setParent paneArrangement`;
  372.  
  373.     // Determine what tab layout is currently active, and which tab layout the
  374.     // tab is being moved to.
  375.     //
  376.     int $activePaneIndex;
  377.  
  378.     $activePaneIndex = `paneLayout -query -activePaneIndex $paneLayout`;
  379.  
  380.     return $activePaneIndex;
  381. }
  382.  
  383. proc string activeTabLayout(
  384.     string $panel)
  385. {
  386.     //
  387.     // Description:
  388.     //    This procedure determines the name of the tab layout in the active
  389.     //    pane of the hypershade panel.
  390.     //
  391.     // Returns: 
  392.     //    The name of the tab layout in the active pane of the hypershade panel.
  393.     //
  394.  
  395.     // Remember the current parent so we can revert to it when we're done here.
  396.     //
  397.     string $oldParent = `setParent -query`;
  398.     string $oldMenuParent = `setParent -menu -query`;
  399.  
  400.     setParent $panel;
  401.  
  402.     string $activeTabLayout; 
  403.  
  404.     string $tabSectionsShown = 
  405.         `optionVar -query hyperShadePanelTabSectionsShown`;
  406.     
  407.     if ($tabSectionsShown == "showTopAndBottomTabs")
  408.     {
  409.         $activeTabLayout = `paneLayout -query -activePane paneArrangement`; 
  410.     }
  411.     else if ($tabSectionsShown == "showTopTabsOnly")
  412.     {
  413.         $activeTabLayout = "firstPaneTabs";
  414.     }
  415.     else // ($tabSectionsShown == "showBottomTabsOnly")
  416.     {
  417.         $activeTabLayout = "secondPaneTabs";
  418.     }
  419.  
  420.     $activeTabLayout = `setParent $activeTabLayout`;
  421.  
  422.     // Revert to the original parent.
  423.     //
  424.     if ($oldParent != "NONE") setParent $oldParent;
  425.     if ($oldMenuParent != "NONE") setParent -menu $oldMenuParent;
  426.  
  427.     return $activeTabLayout;
  428. }
  429.  
  430. proc string activeTab(
  431.     string $panel)
  432. {
  433.     //
  434.     // Description:
  435.     //    This procedure determines the name of the frontmost tab in the tab 
  436.     //    layout in the active pane of the hypershade panel.
  437.     //
  438.     // Returns: 
  439.     //    The name of the tab.
  440.     //
  441.  
  442.     // Remember the current parent so we can revert to it when we're done here.
  443.     //
  444.     string $oldParent = `setParent -query`;
  445.     string $oldMenuParent = `setParent -menu -query`;
  446.  
  447.     string $activeTabLayout = activeTabLayout($panel);
  448.  
  449.     setParent $activeTabLayout;
  450.     
  451.     string $activeTab;
  452.     $activeTab = `tabLayout -query -selectTab $activeTabLayout`;
  453.     $activeTab = `setParent $activeTab`;
  454.  
  455.     // Revert to the original parent.
  456.     //
  457.     if ($oldParent != "NONE") setParent $oldParent;
  458.     if ($oldMenuParent != "NONE") setParent -menu $oldMenuParent;
  459.  
  460.     return $activeTab;
  461. }
  462.  
  463. proc string activeTabIndex(
  464.     string $panel)
  465. {
  466.     //
  467.     // Description:
  468.     //    This procedure determines the index of the frontmost tab in the tab 
  469.     //    layout in the active pane of the hypershade panel.
  470.     //
  471.     // Returns: 
  472.     //    The index of the tab within the active tab layout.
  473.     //
  474.  
  475.     string $activeTabLayout = activeTabLayout($panel);
  476.     
  477.     int $activeTabIndex;
  478.     $activeTabIndex = `tabLayout -query -selectTabIndex $activeTabLayout`;
  479.  
  480.     return $activeTabIndex;
  481. }
  482.  
  483. proc string activeTabLabel(
  484.     string $panel)
  485. {
  486.     //
  487.     // Description:
  488.     //    This procedure determines the label of the frontmost tab in the tab 
  489.     //    layout in the active pane of the hypershade panel.
  490.     //
  491.     // Returns: 
  492.     //    The label of the tab.
  493.     //
  494.  
  495.     // Remember the current parent so we can revert to it when we're done here.
  496.     //
  497.     string $oldParent = `setParent -query`;
  498.     string $oldMenuParent = `setParent -menu -query`;
  499.  
  500.     setParent $panel;
  501.     string $activeTabLayout = activeTabLayout($panel);
  502.     int $activeTabIndex = activeTabIndex($panel);
  503.  
  504.     string $tabLabelArray[];
  505.     $tabLabelArray = `tabLayout -query -tabLabel $activeTabLayout`;
  506.  
  507.     // Revert to the original parent.
  508.     //
  509.     if ($oldParent != "NONE") setParent $oldParent;
  510.     if ($oldMenuParent != "NONE") setParent -menu $oldMenuParent;
  511.  
  512.     return $tabLabelArray[$activeTabIndex - 1];
  513. }
  514.  
  515.  
  516. proc string workAreaTab()
  517. {
  518.     //
  519.     // Description:
  520.     //    This procedure determines the name of the graph tab which is used as
  521.     //    the designated work area (the tab to which graphs should be drawn if no
  522.     //    other graph tab is a more obvious choice).
  523.     //    The designated work area tab should be the only protected graph tab in
  524.     //    the hypershade panel.
  525.     //
  526.     // Returns: 
  527.     //    The name of the designated work area tab.
  528.     //
  529.  
  530.     string $workAreaTab;
  531.     $workAreaTab = `optionVar -q hyperShadePanelWorkAreaTab`;
  532.  
  533.     if ($workAreaTab == "")
  534.     {
  535.         error 
  536.             -showLineNumber true 
  537.             ("Designated Work Area graph tab not found!");
  538.     }
  539.  
  540.     return $workAreaTab;
  541. }
  542.  
  543. proc int isGraphTabVisible(
  544.     string $panel)
  545. {
  546.     //
  547.     // Description:
  548.     //    This procedure determines if a graph tab (work area) is visible within
  549.     //    either of the two tab sections of the hypershade panel.
  550.     //
  551.     // Returns: 
  552.     //    True if at least one of the two tab sections has a graph tab as the
  553.     //    frontmost tab.
  554.     //    False otherwise.
  555.     //
  556.  
  557.     string $saveParent = `setParent -query`;
  558.     string $saveParentMenu = `setParent -query -menu`;
  559.     int    $result = false;
  560.  
  561.     // Determine the names of the tabs in the two tab sections
  562.     //
  563.     setParent $panel;
  564.     $tabLayout = `setParent firstPaneTabs`;
  565.     string $frontFirstPaneTab = 
  566.         ($tabLayout + "|" +`tabLayout -query -selectTab $tabLayout`);
  567.  
  568.     setParent $panel;
  569.     $tabLayout = `setParent secondPaneTabs`;
  570.     string $frontSecondPaneTab = 
  571.         ($tabLayout + "|" +`tabLayout -query -selectTab $tabLayout`);
  572.     
  573.     // Determine if a graph tab is currently frontmost in either tab section
  574.     //
  575.     if (    isGraphTab($frontFirstPaneTab)
  576.         ||     isGraphTab($frontSecondPaneTab))
  577.     {
  578.         $result = true;
  579.     }
  580.     else
  581.     {
  582.         $result =  false;
  583.     }
  584.  
  585.     setParent $saveParent;
  586.     setParent -menu $saveParentMenu;
  587.  
  588.     return $result;
  589. }
  590.  
  591. proc string targetGraphTab(
  592.     string $panel)
  593. {
  594.     //
  595.     // Description:
  596.     //    This procedure is called when the user is performing an action which
  597.     //    should affect a graph tab (work area). For example, if the user has
  598.     //    pressed the Show Up and Downstream Connections button, the resulting
  599.     //    graph must be displayed in a graph tab.
  600.     //    This procedure determines which graph tab would be the most appropriate
  601.     //    graph tab in which to perform the action. The decision is made as
  602.     //    follows: 
  603.     //        If there is only one graph tab visible, it will be the target.
  604.     //        Else if there are two graph tabs visible, the one in the active pane
  605.     //        will be the target.
  606.     //        Else the default work area tab will be the target.
  607.     //
  608.     // Returns: 
  609.     //    The name of the graph tab which is the most appropriate target for an
  610.     //    operation affecting a graph tab at the time this procedure is called.
  611.     //
  612.  
  613.     // Determine which tab layout is currently active
  614.     //
  615.     int     $activePaneIndex = activePaneIndex($panel);
  616.     string     $activeTabLayout;
  617.     string     $inactiveTabLayout;
  618.  
  619.     if ($activePaneIndex == 1) 
  620.     {
  621.         $activeTabLayout = "firstPaneTabs";
  622.         $inactiveTabLayout = "secondPaneTabs";
  623.     }
  624.     else 
  625.     {
  626.         $inactiveTabLayout = "firstPaneTabs";
  627.         $activeTabLayout = "secondPaneTabs";
  628.     }
  629.  
  630.     // Determine the names of the tabs in the active and inactive tab sections
  631.     //
  632.     string $targetTab;
  633.  
  634.     setParent $panel;
  635.     $tabLayout = `setParent $activeTabLayout`;
  636.     string $frontActiveTab = 
  637.         ($tabLayout + "|" +`tabLayout -query -selectTab $tabLayout`);
  638.  
  639.     setParent $panel;
  640.     $tabLayout = `setParent $inactiveTabLayout`;
  641.     string $frontInactiveTab = 
  642.         ($tabLayout + "|" +`tabLayout -query -selectTab $tabLayout`);
  643.     
  644.     // Decide which graph tab should be the target 
  645.     //
  646.     if (isGraphTab($frontActiveTab))
  647.     {
  648.         // The frontmost tab in the active tab section is a graph tab.
  649.         // Therefore we will consider it to be the target tab.
  650.         //
  651.         $targetTab = $frontActiveTab;
  652.     }
  653.     else if (isGraphTab($frontInactiveTab))
  654.     {
  655.         // The frontmost tab in the active tab section is not a graph tab, but
  656.         // the frontmost tab in the inactive tab section is. We will consider
  657.         // the graph tab in the inactive tab section to be the target tab.
  658.         //
  659.         $targetTab = $frontInactiveTab;
  660.     }
  661.     else
  662.     {
  663.         // Neither tab section has a graph tab frontmost. Therefore we will
  664.         // consider the target tab to be the default work area tab.
  665.         //
  666.         $targetTab = workAreaTab();
  667.     }
  668.  
  669.     return $targetTab;
  670. }
  671.  
  672. proc string renderCreateBarUIName(
  673.     string $panel)
  674. {
  675.     //
  676.     // Description:
  677.     //    This procedure determines and returns the name of the top level
  678.     //    formLayout of the renderCreateBarUI. The name can then be used to call
  679.     //    renderCreateBarUI procedures.
  680.     //
  681.     // Returns: 
  682.     //    The name of the layout.
  683.     //
  684.  
  685.     // Remember the current parent so we can revert to it when we're done here.
  686.     //
  687.     string $oldParent = `setParent -query`;
  688.     string $oldMenuParent = `setParent -menu -query`;
  689.  
  690.     setParent $panel;
  691.     string $childArray[] = `formLayout -query -childArray createBarForm`;
  692.  
  693.     string $renderCreateBarUIName = $childArray[0];
  694.  
  695.     // Revert to the original parent.
  696.     //
  697.     if ($oldParent != "NONE") setParent $oldParent;
  698.     if ($oldMenuParent != "NONE") setParent -menu $oldMenuParent;
  699.  
  700.     return $renderCreateBarUIName;
  701. }
  702.  
  703. // ---------------------------------------------------------------------------
  704. //     Procedures to save/access information in option vars about the tab 
  705. //    layouts and settings of individual tabs
  706. // 
  707. proc string tabLabel(
  708.     string $tab)
  709. {
  710.     //
  711.     // Description:
  712.     //    This procedure determines the label of the specified tab.
  713.     //
  714.     // Returns: 
  715.     //    The label of the specified tab.
  716.     //
  717.  
  718.     // Remember the current parent so we can revert to it when we're done here.
  719.     //
  720.     string $oldParent = `setParent -query`;
  721.     string $oldMenuParent = `setParent -menu -query`;
  722.  
  723.     string $tabLabel = "";
  724.  
  725.     setParent $tab;
  726.     setParent ..;
  727.     string $tabLayout = `setParent -query`;
  728.     string $tabLabelArray[] = `tabLayout -query -tabLabel $tabLayout`;
  729.     string $tabArray[] = `tabLayout -query -childArray $tabLayout`;
  730.  
  731.     int $i;
  732.  
  733.     for ($i = 0; ($i < size($tabArray)) && ($tabLabel == ""); $i++)
  734.     {
  735.         setParent $tabLayout;
  736.         $tabArray[$i] = `setParent $tabArray[$i]`;
  737.  
  738.         if ($tabArray[$i] == $tab)
  739.         {
  740.             $tabLabel = $tabLabelArray[$i];
  741.         }
  742.     }
  743.  
  744.     // Revert to the original parent.
  745.     //
  746.     if ($oldParent != "NONE") setParent $oldParent;
  747.     if ($oldMenuParent != "NONE") setParent -menu $oldMenuParent;
  748.  
  749.     return $tabLabel;
  750. }
  751.  
  752. proc string generateUniqueTabOptionVarName()
  753. {
  754.     //
  755.     // Description:
  756.     //    This procedure is used to create a unique name for an optionVar in
  757.     //    which information about a tab will be stored.
  758.     //
  759.     // Returns: 
  760.     //    A unique name for an optionVar.
  761.     //
  762.  
  763.     int $i = 1;
  764.     string $optionVarName;
  765.  
  766.     do
  767.     {
  768.         $optionVarName = ("hyperShadeTab" + $i);
  769.         $i++;
  770.     }
  771.     while (`optionVar -exists $optionVarName`);
  772.  
  773.     return $optionVarName;
  774. }
  775.  
  776. proc updateTabOptionVar(
  777.     string $optionVar,
  778.     string $tab)
  779. {
  780.     //
  781.     // Description:
  782.     //    This procedure is called from updateTabOptionVar() and from
  783.     //    createTabOptionVar(). It encapsulates some shared functionality of the
  784.     //    two other procedures. 
  785.     //    This procedure generates a unique name for a tab option var if no name
  786.     //    is provided in $optionVar. This procedure looks up the type of the tab
  787.     //    in the lookup table if the type is not specified in $type.
  788.     //    This procedure then gathers all of the information about the specified
  789.     //    tab which needs to be stored in the optionVar, and saves that
  790.     //    information in the optionVar in a known format.
  791.     //    
  792.  
  793.     if ($optionVar == "")
  794.     {
  795.         // No optionVar name was specified, so we create a new one.
  796.         //
  797.         $optionVar = generateUniqueTabOptionVarName();
  798.     }
  799.  
  800.     //
  801.     // Now we gather all of the information we need to store about the tab.
  802.     //
  803.  
  804.     string $tabLabel = tabLabel($tab);
  805.     string $type = lookupTabType($tab);
  806.     string $component = lookupComponentName($tab);
  807.  
  808.     optionVar -intValue $optionVar 1;
  809.     optionVar -stringValue ($optionVar + "Label") $tabLabel;
  810.     optionVar -stringValue ($optionVar + "Type") $type;
  811.  
  812.     if ($type == "disk")
  813.     {
  814.         optionVar 
  815.             -stringValue ($optionVar + "DirectoriesVisorName") 
  816.             `libraryUIDirectoriesVisor($component)`;
  817.         optionVar 
  818.             -stringValue ($optionVar + "FilesVisorName") 
  819.             `libraryUIFilesVisor($component)`;
  820.         optionVar 
  821.             -stringValue ($optionVar + "RootDirectory") 
  822.             `libraryUIRootDirectory($component)`;
  823.         optionVar 
  824.             -stringValue ($optionVar + "CurrentDirectory") 
  825.             `libraryUICurrentDirectory($component)`;
  826.         optionVar 
  827.             -intValue ($optionVar + "DirectoriesShown") 
  828.             `libraryUIDirectoriesShown($component)`;
  829.         optionVar 
  830.             -intValue ($optionVar + "FilesShown") 
  831.             `libraryUIFilesShown($component)`;
  832.     }
  833.     else if (($type == "graph") || ($type == "protected graph"))
  834.     {
  835.         optionVar 
  836.             -stringValue ($optionVar + "HypershadeName") 
  837.             `graphUIHypershadeName($component)`;
  838.     }
  839.     else if ($type == "scene")
  840.     {
  841.         optionVar 
  842.             -stringValue ($optionVar + "HypershadeName") 
  843.             `collectionUIHypershadeName($component)`;
  844.         optionVar 
  845.             -stringValue ($optionVar + "Filter") 
  846.             `collectionUIFilter($component)`;
  847.     }
  848.     else
  849.     {
  850.         error
  851.             -showLineNumber true
  852.             ("Unexpected tab type: " + $type);
  853.     }
  854. }
  855.  
  856. proc setTabLabel(
  857.     string $tab,
  858.     string $label)
  859. {
  860.     //
  861.     // Description:
  862.     //    This procedure sets the label of the specified tab.
  863.     //
  864.  
  865.     // Remember the current parent so we can revert to it when we're done here.
  866.     //
  867.     string $oldParent = `setParent -query`;
  868.     string $oldMenuParent = `setParent -menu -query`;
  869.  
  870.     setParent $tab;
  871.     setParent ..;
  872.     string $tabLayout = `setParent -query`;
  873.     string $tabLabelArray[] = `tabLayout -query -tabLabel $tabLayout`;
  874.     string $tabArray[] = `tabLayout -query -childArray $tabLayout`;
  875.  
  876.     int $i;
  877.     string $shortTabName;
  878.     int $found = false;
  879.  
  880.     for ($i = 0; ($i < size($tabArray)) && (!$found); $i++)
  881.     {
  882.         setParent $tabLayout;
  883.         $shortTabName = $tabArray[$i];
  884.         $tabArray[$i] = `setParent $tabArray[$i]`;
  885.  
  886.         if ($tabArray[$i] == $tab)
  887.         {
  888.             $found = true;
  889.         }
  890.     }
  891.  
  892.     if ($found)
  893.     {
  894.         tabLayout
  895.             -edit
  896.             -tabLabel $shortTabName $label
  897.             $tabLayout;
  898.     }
  899.  
  900.     // Save the new tab label so that it will be remembered the next time the
  901.     // visor is opened.
  902.     //
  903.     string $optionVar = lookupTabOptionVar($tab);
  904.     updateTabOptionVar($optionVar, $tab);
  905.  
  906.     // Revert to the original parent.
  907.     //
  908.     if ($oldParent != "NONE") setParent $oldParent;
  909.     if ($oldMenuParent != "NONE") setParent -menu $oldMenuParent;
  910. }
  911.  
  912. proc string tabTypeFromOptionVar(
  913.     string $optionVar)
  914. {
  915.     //
  916.     // Description:
  917.     //    This procedure retrieves the type of the tab whose information is
  918.     //    stored in the specified optionVar.
  919.     //
  920.     // Returns: 
  921.     //    The type of the tab.
  922.     //
  923.  
  924.     string $valueArray[];
  925.     $valueArray = `optionVar -query $optionVar`;
  926.  
  927.     return $valueArray[0];
  928. }
  929.  
  930. proc string tabLabelFromOptionVar(
  931.     string $optionVar)
  932. {
  933.     //
  934.     // Description:
  935.     //    This procedure retrieves the label of the tab whose information is
  936.     //    stored in the specified optionVar.
  937.     //
  938.     // Returns: 
  939.     //    The label of the tab.
  940.     //
  941.  
  942.     string $valueArray[];
  943.     $valueArray = `optionVar -query $optionVar`;
  944.  
  945.     return $valueArray[1];
  946. }
  947.  
  948. proc deleteOptionVar(
  949.     string $optionVar)
  950. {
  951.     //
  952.     // Description:
  953.     //    This method is called from deleteTabOptionVar() or from
  954.     //    deleteUnusedOptionVars(). 
  955.     //    This method deletes the specified optionVar and the optionVars related
  956.     //    to it.
  957.     //    The specified optionVar actually serves no purpose except to act as a
  958.     //    prefic for the related optionVars.
  959.     //
  960.  
  961.     optionVar -remove $optionVar;
  962.     optionVar -remove ($optionVar + "Label");
  963.     optionVar -remove ($optionVar + "Type");
  964.     optionVar -remove ($optionVar + "DirectoriesVisorName");
  965.     optionVar -remove ($optionVar + "FilesVisorName");
  966.     optionVar -remove ($optionVar + "RootDirectory"); 
  967.     optionVar -remove ($optionVar + "CurrentDirectory"); 
  968.     optionVar -remove ($optionVar + "DirectoriesShown");
  969.     optionVar -remove ($optionVar + "FilesShown"); 
  970.     optionVar -remove ($optionVar + "HypershadeName");
  971.     optionVar -remove ($optionVar + "Filter");
  972. }
  973.  
  974. proc deleteTabOptionVar(
  975.     string $tab)
  976. {
  977.     //
  978.     // Description:
  979.     //    This procedure deletes the optionVar associated with the specified tab.
  980.     //
  981.  
  982.     string $optionVar = lookupTabOptionVar($tab);
  983.     deleteOptionVar($optionVar);
  984. }
  985.  
  986. proc deleteUnusedTabOptionVars(
  987.     string $panel)
  988. {
  989.     //
  990.     // Description:
  991.     //    This procedure is called the first time hypershade is opened each
  992.     //    session.
  993.     //    This procedure deletes all optionVars whose names indicate that they
  994.     //    contain information about hypershade panel tabs, but which are not
  995.     //    being used for some reason. This is done so that the user's userPrefs
  996.     //    does not fill up with unused optionVars.
  997.     //
  998.  
  999.     int $i;
  1000.  
  1001.     for ($i = 0; $i < 100; $i++)
  1002.     {
  1003.         string $optionVar = ("hyperShadeTab" + $i);
  1004.         if (`optionVar -exists $optionVar`)
  1005.         {
  1006.             if (lookupOptionVarTab($optionVar) == "")
  1007.             {
  1008.                 deleteOptionVar($optionVar);
  1009.             }
  1010.         }
  1011.     }
  1012. }
  1013.  
  1014. proc updateTabLayoutOptionVar(
  1015.     string $panel,
  1016.     string $tabLayout)
  1017. {
  1018.     //
  1019.     // Description:
  1020.     //    This procedure should be called whenever a change is made to the tab
  1021.     //    layouts in the hypershade panel which we want to save to an optionVar
  1022.     //    in order to be able to recreate the same tab layout structure at a
  1023.     //    later time. For example, we would want to call this procedure if we had
  1024.     //    moved a tab left or right within the tab layout.
  1025.     //    This procedure writes out an option var which names all of the option
  1026.     //    vars describing properties of the tabs in the specified tab layout. 
  1027.     //    The tab option vars are named in order from left to right.
  1028.     //
  1029.  
  1030.     string $oldParent = `setParent -query`;
  1031.     setParent $panel;
  1032.  
  1033.     // Get the short name of the tab layout, since the caller may have passed
  1034.     // in the full path
  1035.     //
  1036.     string $tabLayoutPathTokens[];
  1037.     tokenize($tabLayout, "|", $tabLayoutPathTokens);
  1038.     $tabLayout = $tabLayoutPathTokens[size($tabLayoutPathTokens) - 1];
  1039.  
  1040.     string $tabLayoutOptionVar;
  1041.  
  1042.     if ($tabLayout == "firstPaneTabs")
  1043.     {
  1044.         $tabLayoutOptionVar = "hyperShadeFirstPaneTabs";
  1045.     }
  1046.     else if ($tabLayout == "secondPaneTabs")
  1047.     {
  1048.         $tabLayoutOptionVar = "hyperShadeSecondPaneTabs";
  1049.     }
  1050.     else
  1051.     {
  1052.         error
  1053.             -showLineNumber true
  1054.             ("Unexpected tab layout name specified: " + $tabLayout + ".");
  1055.     }
  1056.  
  1057.     // Delete the existing optionVar for the tabs in this pane, because we are
  1058.     // going to rebuild it.
  1059.     //
  1060.     optionVar -remove $tabLayoutOptionVar;
  1061.  
  1062.     // Unmanage the tabLayout because what we are about to do can cause some
  1063.     // flicker.
  1064.     //
  1065.     tabLayout -edit -manage false $tabLayout;
  1066.  
  1067.     // Take note of the currently selected tab because we will be changing the
  1068.     // tab selection and will want to restore the current selection later
  1069.     //
  1070.     int $selectedTabIndex = `tabLayout -query -selectTabIndex $tabLayout`;
  1071.  
  1072.     int $numTabs = `tabLayout -query -numberOfChildren $tabLayout`;
  1073.     string $tabArray[];
  1074.     int $i;
  1075.  
  1076.     // For each tab in the tabLayout of the first pane
  1077.     //
  1078.     for ($i = 0; $i < $numTabs; $i++)
  1079.     {
  1080.         // Select the tab and query the layout associated with the selected
  1081.         // tab. The name of the layout is stored in $tabArray and will be used
  1082.         // later as the key to be used in looking up the optionVar of the tab
  1083.         // in the lookup table.
  1084.         //
  1085.         // Previously, a more straightforward approach of using the tabLayout
  1086.         // -childArray flag was used, but it turned out the -childArray flag
  1087.         // does not return the names of the children in the order in which they
  1088.         // appear in the tab layout, but instead in the order in which they
  1089.         // were added to the tab layout.
  1090.         //
  1091.         tabLayout -edit -selectTabIndex ($i + 1) $tabLayout;
  1092.         $tabArray[$i] = `tabLayout -query -selectTab $tabLayout`;
  1093.     }
  1094.  
  1095.     // Reselect the previously selected tab
  1096.     //
  1097.     tabLayout -edit -selectTabIndex $selectedTabIndex $tabLayout;
  1098.  
  1099.     // Remanage the tab layout
  1100.     //
  1101.     tabLayout -edit -manage true $tabLayout;
  1102.  
  1103.     //
  1104.     // Now that we have a list of the layouts associated with the tabs, we can
  1105.     // lookup the name of the optionVar associated with each and store it in
  1106.     // the optionVar which describes the ordering of the tabs.
  1107.     //
  1108.  
  1109.     string $tab;
  1110.     string $tabOptionVar;
  1111.  
  1112.     // For each tab in the tabLayout of the first pane
  1113.     //
  1114.     for ($i = 0; $i < size($tabArray); $i++)
  1115.     {
  1116.         $tab = $tabArray[$i];
  1117.         setParent $panel;
  1118.         $tab = `setParent $tab`;
  1119.  
  1120.         // Lookup the optionVar which describes this tab
  1121.         //
  1122.         $tabOptionVar = lookupTabOptionVar($tab);
  1123.  
  1124.         if ($tabOptionVar == "")
  1125.         {
  1126.             global string $gHyperShadePanelLookupTable[];
  1127.             lookupTablePrint($gHyperShadePanelLookupTable);
  1128.  
  1129.             error
  1130.                 -showLineNumber true
  1131.                 ("Expected lookup table to contain "
  1132.                     + "non-empty tab option var name.");
  1133.         }
  1134.  
  1135.         // Append the name of the optionVar to the optionVar describing the
  1136.         // tabs in this pane
  1137.         //
  1138.         optionVar -stringValueAppend $tabLayoutOptionVar $tabOptionVar;
  1139.     }
  1140.  
  1141.     if ($oldParent != "NONE") setParent $oldParent;
  1142. }
  1143.  
  1144. // ---------------------------------------------------------------------------
  1145. //     UI creation procedures
  1146. // 
  1147.  
  1148. proc string createGraphTab(
  1149.     string $panel,
  1150.     string $tabLayout,
  1151.     string $tabLabel,
  1152.     int $protected)
  1153. {
  1154.     //
  1155.     // Description:
  1156.     //    This procedure is called when the user creates a new graph tab, or when
  1157.     //    the default tabs are being created (ie the first time the user uses the
  1158.     //    hypershade panel or as a result of a revert to default tabs). 
  1159.     //    This procedure creates a graph tab.
  1160.     //    If the $protected argument is true, this tab will be flagged as a
  1161.     //    protected graph. A protected graph is one which cannot be removed from
  1162.     //    the hypershade panel or moved from one tab layout to the other within
  1163.     //    the hypershade panel. 
  1164.     //
  1165.     // Returns: 
  1166.     //    The name of the newly created tab.
  1167.     //
  1168.  
  1169.     setParent $panel;
  1170.     setParent $tabLayout;
  1171.         string $tab = `formLayout`;
  1172.             // Create the graph UI. The second parameter is blank
  1173.             // because we want to have a new hypershade created,
  1174.             // rather than specifying an existing one to be used.
  1175.             //
  1176.             string $graphUI = 
  1177.                 graphUI(
  1178.                     $tab, 
  1179.                     ""); // hypershadeName
  1180.         setParent ..; // from $tab
  1181.     setParent ..; // from $tabLayout
  1182.  
  1183.     // Set the label on the tab
  1184.     //
  1185.     tabLayout
  1186.         -edit
  1187.         -tabLabel $tab $tabLabel
  1188.         $tabLayout;
  1189.  
  1190.     // Configure the graphUI
  1191.     //
  1192.     graphUISetPopupMenuScript(
  1193.         $graphUI, 
  1194.         ("hyperShadePanelSceneAndGraphTabPopupMenu " + $panel));
  1195.  
  1196.     string $hypershadeName = graphUIHypershadeName($graphUI);
  1197.  
  1198.     // Create a callback to set the active pane when mouse is pressed.
  1199.     //
  1200.     hyperGraph -edit
  1201.         -focusCommand 
  1202.             ("hyperShadePanelSetActiveTabLayout "
  1203.                 + $panel
  1204.                 + " "
  1205.                 + $tabLayout)
  1206.         $hypershadeName;
  1207.     
  1208.     // Specify the callback to be called when the user clicks on the menu arrow
  1209.     // on the bottom of a node
  1210.     //
  1211.     hyperGraph 
  1212.         -edit
  1213.         -nodeMenuCommand 
  1214.             ("hyperShadePanelSceneAndGraphTabPopupMenu " + $panel)
  1215.         $hypershadeName;
  1216.  
  1217.     string $optionVar = generateUniqueTabOptionVarName();
  1218.     if ($protected)
  1219.     {
  1220.         // A protected graph is one which cannot be removed or moved to the
  1221.         // other tab layout. It *can* be moved left and right within the tab
  1222.         // layout it is in.
  1223.         //
  1224.         registerTab($tab, "protected graph", $graphUI, $optionVar);
  1225.     }
  1226.     else
  1227.     {
  1228.         registerTab($tab, "graph", $graphUI, $optionVar);
  1229.     }
  1230.     updateTabOptionVar($optionVar, $tab);
  1231.  
  1232.     // Update the tab layout option var now that a new tab has been added
  1233.     //
  1234.     updateTabLayoutOptionVar($panel, $tabLayout);
  1235.  
  1236.     // If the graph tab is protected, it should be considered the designated
  1237.     // Work Area tab.
  1238.     //
  1239.     // ASSUMPTION:
  1240.     // We assume there will only ever be one protected tab, since we do not
  1241.     // allow the user to create one. If additional protected graph tabs are
  1242.     // created in the future, this code will need to change.
  1243.     //
  1244.     if ($protected)
  1245.     {
  1246.         optionVar -stringValue "hyperShadePanelWorkAreaTab" $tab;
  1247.     }
  1248.  
  1249.     // Return the name of the tab which was created.
  1250.     //
  1251.     return $tab;
  1252. }
  1253.  
  1254. proc string recreateGraphTab(
  1255.     string $panel,
  1256.     string $tabLayout,
  1257.     string $optionVar, 
  1258.     int $reuseEditors,
  1259.     int $protected)
  1260. {
  1261.     //
  1262.     // Description:
  1263.     //    This procedure is called when a graph tab is being recreated from an
  1264.     //    optionVar.
  1265.     //    This procedure creates a graph tab using the information stored in the
  1266.     //    specified optionVar.
  1267.     //    If the $protected argument is true, this tab will be flagged as a
  1268.     //    protected graph. A protected graph is one which cannot be removed from
  1269.     //    the hypershade panel or moved from one tab layout to the other within
  1270.     //    the hypershade panel. 
  1271.     //
  1272.     // Returns: 
  1273.     //    The name of the newly created tab.
  1274.     //
  1275.  
  1276.     string $tabLabel 
  1277.         = `optionVar -query ($optionVar + "Label")`;
  1278.     string $hypershadeName;
  1279.  
  1280.     if ($reuseEditors)
  1281.     {
  1282.         $hypershadeName = `optionVar -query ($optionVar + "HypershadeName")`;
  1283.     }
  1284.  
  1285.     setParent $panel;
  1286.     setParent $tabLayout;
  1287.         string $tab = `formLayout`;
  1288.             // Create the graph UI specifying that an existing hypershade
  1289.             // should be used.
  1290.             //
  1291.             string $graphUI = 
  1292.                 graphUI(
  1293.                     $tab, 
  1294.                     $hypershadeName);
  1295.         setParent ..; // from $tab
  1296.     setParent ..; // from $tabLayout
  1297.  
  1298.     // Set the label on the tab
  1299.     //
  1300.     tabLayout
  1301.         -edit
  1302.         -tabLabel $tab $tabLabel
  1303.         $tabLayout;
  1304.  
  1305.     // Configure the graphUI according to saved state
  1306.     //
  1307.     graphUISetPopupMenuScript(
  1308.         $graphUI, 
  1309.         ("hyperShadePanelSceneAndGraphTabPopupMenu " + $panel));
  1310.  
  1311.     // Create a callback to set the active pane when mouse is pressed.
  1312.     //
  1313.     string $hypershadeName = graphUIHypershadeName($graphUI);
  1314.  
  1315.     hyperGraph -edit
  1316.         -focusCommand 
  1317.             ("hyperShadePanelSetActiveTabLayout "
  1318.                 + $panel
  1319.                 + " "
  1320.                 + $tabLayout)
  1321.         $hypershadeName;
  1322.  
  1323.     // Specify the callback to be called when the user clicks on the menu arrow
  1324.     // on the bottom of a node
  1325.     //
  1326.     hyperGraph 
  1327.         -edit
  1328.         -nodeMenuCommand 
  1329.             ("hyperShadePanelSceneAndGraphTabPopupMenu " + $panel)
  1330.         $hypershadeName;
  1331.  
  1332.     if ($protected)
  1333.     {
  1334.         registerTab($tab, "protected graph", $graphUI, $optionVar);
  1335.     }
  1336.     else
  1337.     {
  1338.         registerTab($tab, "graph", $graphUI, $optionVar);
  1339.     }
  1340.  
  1341.     // Update the tab layout option var now that a new tab has been added
  1342.     //
  1343.     updateTabLayoutOptionVar($panel, $tabLayout);
  1344.  
  1345.     // If the graph tab is protected, it should be considered the designated
  1346.     // Work Area tab.
  1347.     //
  1348.     // ASSUMPTION:
  1349.     // We assume there will only ever be one protected tab, since we do not
  1350.     // allow the user to create one. If additional protected graph tabs are
  1351.     // created in the future, this code will need to change.
  1352.     //
  1353.     if ($protected)
  1354.     {
  1355.         optionVar -stringValue "hyperShadePanelWorkAreaTab" $tab;
  1356.     }
  1357.  
  1358.     // Return the name of the tab which was created.
  1359.     //
  1360.     return $tab;
  1361. }
  1362.  
  1363. proc string createDiskTab(
  1364.     string $panel,
  1365.     string $tabLayout,
  1366.     string $tabLabel,
  1367.     string $directory)
  1368. {
  1369.     //
  1370.     // Description:
  1371.     //    This procedure is called when the user creates a new disk tab, or when
  1372.     //    the default tabs are being created (ie the first time the user uses the
  1373.     //    hypershade panel or as a result of a revert to default tabs). 
  1374.     //    This procedure creates a disk tab.
  1375.     //
  1376.     // Returns: 
  1377.     //    The name of the newly created tab.
  1378.     //
  1379.  
  1380.     setParent $panel;
  1381.     setParent $tabLayout;
  1382.         string $tab = `formLayout`;
  1383.             // Create the library UI. The second and third parameters are blank
  1384.             // because we want to have new directory and files visors created,
  1385.             // rather than specifying existing ones to be used.
  1386.             //
  1387.             string $libraryUI = 
  1388.                 libraryUI(
  1389.                     $tab, 
  1390.                     "",     // directoriesVisorName
  1391.                     "");     // filesVisorName
  1392.             libraryUISetRootDirectory($libraryUI, $directory);
  1393.         setParent ..; // from $tab
  1394.     setParent ..; // from $tabLayout
  1395.  
  1396.     // Set the label on the tab
  1397.     //
  1398.     tabLayout
  1399.         -edit
  1400.         -tabLabel $tab $tabLabel
  1401.         $tabLayout;
  1402.     
  1403.     // Create a callback to set the active pane when mouse is pressed.
  1404.     //
  1405.     {
  1406.         string $directoriesName = libraryUIDirectoriesVisor($libraryUI);
  1407.  
  1408.         hyperGraph -edit
  1409.             -focusCommand 
  1410.                 ("hyperShadePanelSetActiveTabLayout "
  1411.                     + $panel
  1412.                     + " "
  1413.                     + $tabLayout)
  1414.             $directoriesName;
  1415.  
  1416.         string $filesName = libraryUIFilesVisor($libraryUI);
  1417.  
  1418.         hyperGraph -edit
  1419.             -focusCommand 
  1420.                 ("hyperShadePanelSetActiveTabLayout "
  1421.                     + $panel
  1422.                     + " "
  1423.                     + $tabLayout)
  1424.             $filesName;
  1425.     }
  1426.  
  1427.     // Configure the libraryUI
  1428.     //
  1429.     libraryUISetFilesPopupMenuScript(
  1430.         $libraryUI, 
  1431.         ("hyperShadePanelDiskTabPopupMenu " + $panel));
  1432.  
  1433.     string $optionVar = generateUniqueTabOptionVarName();
  1434.     registerTab($tab, "disk", $libraryUI, $optionVar);
  1435.     updateTabOptionVar($optionVar, $tab);
  1436.  
  1437.     // Update the tab layout option var now that a new tab has been added
  1438.     //
  1439.     updateTabLayoutOptionVar($panel, $tabLayout);
  1440.  
  1441.     // Return the name of the tab which was created.
  1442.     //
  1443.     return $tab;
  1444. }
  1445.  
  1446. proc string recreateDiskTab(
  1447.     string $panel,
  1448.     string $tabLayout,
  1449.     string $optionVar,
  1450.     int $reuseEditors)
  1451. {
  1452.     //
  1453.     // Description:
  1454.     //    This procedure is called when a disk tab is being recreated from 
  1455.     //    optionVars.
  1456.     //    This procedure creates a disk tab using the information stored in
  1457.     //    optionVars.
  1458.     //
  1459.     // Returns: 
  1460.     //    The name of the newly created tab.
  1461.     //
  1462.  
  1463.     string $tabLabel 
  1464.         = `optionVar -query ($optionVar + "Label")`;
  1465.     string $directoriesVisorName;
  1466.     string $filesVisorName;
  1467.  
  1468.     if ($reuseEditors)
  1469.     {
  1470.         $directoriesVisorName 
  1471.             = `optionVar -query ($optionVar + "DirectoriesVisorName")`;
  1472.         $filesVisorName 
  1473.             = `optionVar -query ($optionVar + "FilesVisorName")`;
  1474.     }
  1475.  
  1476.     setParent $panel;
  1477.     setParent $tabLayout;
  1478.         string $tab = `formLayout`;
  1479.             // Create the library UI specifying that our existing directory and
  1480.             // files visors should be used.
  1481.             //
  1482.             string $libraryUI = 
  1483.                 libraryUI(
  1484.                     $tab, 
  1485.                     $directoriesVisorName,
  1486.                     $filesVisorName);
  1487.         setParent ..; // from $tab
  1488.     setParent ..; // from $tabLayout
  1489.  
  1490.     // Set the label on the tab
  1491.     //
  1492.     tabLayout
  1493.         -edit
  1494.         -tabLabel $tab $tabLabel
  1495.         $tabLayout;
  1496.  
  1497.     // Create a callback to set the active pane when mouse is pressed.
  1498.     //
  1499.     {
  1500.         string $directoriesName = libraryUIDirectoriesVisor($libraryUI);
  1501.  
  1502.         hyperGraph -edit
  1503.             -focusCommand 
  1504.                 ("hyperShadePanelSetActiveTabLayout "
  1505.                     + $panel
  1506.                     + " "
  1507.                     + $tabLayout)
  1508.             $directoriesName;
  1509.  
  1510.         string $filesName = libraryUIFilesVisor($libraryUI);
  1511.  
  1512.         hyperGraph -edit
  1513.             -focusCommand 
  1514.                 ("hyperShadePanelSetActiveTabLayout "
  1515.                     + $panel
  1516.                     + " "
  1517.                     + $tabLayout)
  1518.             $filesName;
  1519.     }
  1520.  
  1521.     //
  1522.     // Configure the libraryUI according to saved state
  1523.     //
  1524.     // For some tabs we may not necessarily use the root directory and current
  1525.     // directory that have been stored in optionVars. In situations where the
  1526.     // tab label indicates that the tab is a "default" tab (ie one you would
  1527.     // get if you did Revert To Default Tabs), we will ensure the directories
  1528.     // point to the current installation of Maya. If we did not do this, we
  1529.     // would have situations where a user running a new installation of Maya
  1530.     // would still end up looking at shader libraries and such from a previous
  1531.     // installation.
  1532.     //
  1533.  
  1534.     // Initialize the root directory and current directory for the tab to be
  1535.     // the directories stored in optionVars.
  1536.     //
  1537.     string $rootDirectory = 
  1538.         `optionVar -query ($optionVar + "RootDirectory")`;
  1539.     string $currentDirectory = 
  1540.         `optionVar -query ($optionVar + "CurrentDirectory")`;
  1541.  
  1542.     // For disk tabs with particular labels, we will massage the directories to
  1543.     // be sure they are appropriate.
  1544.     //
  1545.     if ($tabLabel == "Projects")
  1546.     {
  1547.         string $projectsDir = `internalVar -userWorkspaceDir`;
  1548.         
  1549.         if ($rootDirectory != $projectsDir)
  1550.         {
  1551.             $rootDirectory = $projectsDir;
  1552.             $currentDirectory = $projectsDir;
  1553.         }
  1554.     }
  1555.     else if ($tabLabel == "Shader Library")
  1556.     {
  1557.         string $shaderLibraryDir = `getenv MAYA_SHADER_LIBRARY_PATH`;
  1558.  
  1559.         if (    ($shaderLibraryDir != "")
  1560.             &&    ($rootDirectory != $shaderLibraryDir))
  1561.         {
  1562.             $rootDirectory = $shaderLibraryDir;
  1563.             $currentDirectory = $shaderLibraryDir;
  1564.         }
  1565.     }
  1566.  
  1567.  
  1568.     // Set the root and current directories of the tab
  1569.     //
  1570.     libraryUISetRootDirectory($libraryUI, $rootDirectory);
  1571.     libraryUISetCurrentDirectory($libraryUI, $currentDirectory);
  1572.  
  1573.     if (`optionVar -query ($optionVar + "DirectoriesShown")`)
  1574.     {
  1575.         if (`optionVar -query ($optionVar + "FilesShown")`)
  1576.         {
  1577.             libraryUIShowDirectoriesAndFiles($libraryUI);
  1578.         }
  1579.         else
  1580.         {
  1581.             libraryUIShowDirectoriesOnly($libraryUI);
  1582.         }
  1583.     }
  1584.     else
  1585.     {
  1586.         libraryUIShowFilesOnly($libraryUI);
  1587.     }
  1588.  
  1589.     libraryUISetFilesPopupMenuScript(
  1590.         $libraryUI,
  1591.         ("hyperShadePanelDiskTabPopupMenu " + $panel));
  1592.  
  1593.  
  1594.     registerTab($tab, "disk", $libraryUI, $optionVar);
  1595.  
  1596.     // Update the tab layout option var now that a new tab has been added
  1597.     //
  1598.     updateTabLayoutOptionVar($panel, $tabLayout);
  1599.  
  1600.     // Return the name of the tab which was created.
  1601.     //
  1602.     return $tab;
  1603. }
  1604.  
  1605. proc string createSceneTab(
  1606.     string $panel,
  1607.     string $tabLayout,
  1608.     string $tabLabel,
  1609.     string $filter)
  1610. {
  1611.     //
  1612.     // Description:
  1613.     //    This procedure is called when the user creates a new scene tab, or when
  1614.     //    the default tabs are being created (ie the first time the user uses the
  1615.     //    hypershade panel or as a result of a revert to default tabs). 
  1616.     //    This procedure creates a scene tab.
  1617.     //
  1618.     // Returns: 
  1619.     //    The name of the newly created tab.
  1620.     //
  1621.  
  1622.     setParent $panel;
  1623.     setParent $tabLayout;
  1624.         string $tab = `formLayout`;
  1625.             // Create the collection UI. The second parameter is blank
  1626.             // because we want to have a new hypershade created,
  1627.             // rather than specifying an existing one to be used.
  1628.             //
  1629.             string $collectionUI = 
  1630.                 collectionUI(
  1631.                     $tab, 
  1632.                     ""); // hypershadeName
  1633.         setParent ..; // from $tab
  1634.     setParent ..; // from $tabLayout
  1635.  
  1636.     // Set the label on the tab
  1637.     //
  1638.     tabLayout
  1639.         -edit
  1640.         -tabLabel $tab $tabLabel
  1641.         $tabLayout;
  1642.     
  1643.     // Create a callback to set the active pane when mouse is pressed.
  1644.     //
  1645.     {
  1646.         string $hyperName = collectionUIHypershadeName($collectionUI);
  1647.  
  1648.         hyperGraph -edit
  1649.             -focusCommand 
  1650.                 ("hyperShadePanelSetActiveTabLayout "
  1651.                     + $panel
  1652.                     + " " 
  1653.                     + $tabLayout)
  1654.             $hyperName;
  1655.     }
  1656.  
  1657.     // Configure the collectionUI
  1658.     //
  1659.     collectionUISetFilter($collectionUI, $filter);
  1660.     collectionUISetPopupMenuScript(
  1661.         $collectionUI, 
  1662.         ("hyperShadePanelSceneAndGraphTabPopupMenu " + $panel));
  1663.  
  1664.     string $optionVar = generateUniqueTabOptionVarName();
  1665.     registerTab($tab, "scene", $collectionUI, $optionVar);
  1666.     updateTabOptionVar($optionVar, $tab);
  1667.  
  1668.     // Update the tab layout option var now that a new tab has been added
  1669.     //
  1670.     updateTabLayoutOptionVar($panel, $tabLayout);
  1671.  
  1672.     // Return the name of the tab which was created.
  1673.     //
  1674.     return $tab;
  1675. }
  1676.  
  1677. proc string recreateSceneTab(
  1678.     string $panel,
  1679.     string $tabLayout,
  1680.     string $optionVar,
  1681.     int $reuseEditors)
  1682. {
  1683.     //
  1684.     // Description:
  1685.     //    This procedure is called when a scene tab is being recreated from an
  1686.     //    optionVar.
  1687.     //    This procedure creates a scene tab using the information stored in the
  1688.     //    specified optionVar.
  1689.     //
  1690.     // Returns: 
  1691.     //    The name of the newly created tab.
  1692.     //
  1693.  
  1694.     string $tabLabel 
  1695.         = `optionVar -query ($optionVar + "Label")`;
  1696.     string $hypershadeName;
  1697.  
  1698.     if ($reuseEditors)
  1699.     {
  1700.         $hypershadeName = `optionVar -query ($optionVar + "HypershadeName")`;
  1701.     }
  1702.  
  1703.  
  1704.     setParent $panel;
  1705.     setParent $tabLayout;
  1706.         string $tab = `formLayout`;
  1707.             // Create the graph UI specifying that an existing hypershade
  1708.             // should be used.
  1709.             //
  1710.             string $collectionUI = 
  1711.                 collectionUI(
  1712.                     $tab, 
  1713.                     $hypershadeName);
  1714.  
  1715.         setParent ..; // from $tab
  1716.     setParent ..; // from $tabLayout
  1717.  
  1718.     // Set the label on the tab
  1719.     //
  1720.     tabLayout
  1721.         -edit
  1722.         -tabLabel $tab $tabLabel
  1723.         $tabLayout;
  1724.  
  1725.     // Create a callback to set the active pane when mouse is pressed.
  1726.     //
  1727.     {
  1728.         string $hyperName = collectionUIHypershadeName($collectionUI);
  1729.  
  1730.         hyperGraph -edit
  1731.             -focusCommand 
  1732.                 ("hyperShadePanelSetActiveTabLayout "
  1733.                     + $panel
  1734.                     + " "
  1735.                     + $tabLayout)
  1736.             $hyperName;
  1737.     }
  1738.  
  1739.     // Configure the collectionUI according to saved state
  1740.     //
  1741.     collectionUISetFilter(
  1742.         $collectionUI,
  1743.         `optionVar -query ($optionVar + "Filter")`);
  1744.     collectionUISetPopupMenuScript(
  1745.         $collectionUI, 
  1746.         ("hyperShadePanelSceneAndGraphTabPopupMenu " + $panel));
  1747.  
  1748.  
  1749.     registerTab($tab, "scene", $collectionUI, $optionVar);
  1750.  
  1751.     // Update the tab layout option var now that a new tab has been added
  1752.     //
  1753.     updateTabLayoutOptionVar($panel, $tabLayout);
  1754.  
  1755.     // Return the name of the tab which was created.
  1756.     //
  1757.     return $tab;
  1758. }
  1759.  
  1760. proc recreateTab(
  1761.     string $panel,
  1762.     string $tabLayout,
  1763.     string $optionVar,
  1764.     int $reuseEditors)
  1765. {
  1766.     //
  1767.     // Description:
  1768.     //    This procedure is called by initTabs() when a tab is being recreated 
  1769.     //    from an optionVar.
  1770.     //    This procedure determines what kind of tab is represented by the
  1771.     //    optionVar, then calls one of recreateGraphTab(), recreateDiskTab() or
  1772.     //    recreateSceneTab() to create the tab.
  1773.     //
  1774.  
  1775.     string $type = `optionVar -query ($optionVar + "Type")`;
  1776.  
  1777.     if ($type == "disk")
  1778.     {
  1779.         recreateDiskTab($panel, $tabLayout, $optionVar, $reuseEditors);
  1780.     }
  1781.     else if ($type == "graph")
  1782.     {
  1783.         recreateGraphTab(
  1784.             $panel, 
  1785.             $tabLayout, 
  1786.             $optionVar, 
  1787.             $reuseEditors,
  1788.             false);
  1789.     }
  1790.     else if ($type == "protected graph")
  1791.     {
  1792.         recreateGraphTab(
  1793.             $panel, 
  1794.             $tabLayout, 
  1795.             $optionVar, 
  1796.             $reuseEditors,
  1797.             true);
  1798.     }
  1799.     else if ($type == "scene")
  1800.     {
  1801.         recreateSceneTab($panel, $tabLayout, $optionVar, $reuseEditors);
  1802.     }
  1803.     else
  1804.     {
  1805.         error
  1806.             -showLineNumber true
  1807.             ("Unexpected tab type in option var: " + $type );
  1808.     }
  1809. }
  1810.  
  1811. proc moveTab(
  1812.     string $panel,
  1813.     string $direction)
  1814. {
  1815.     //
  1816.     // Description:
  1817.     //    This procedure moves a tab up, down, left or right within the
  1818.     //    hypershade panel. 
  1819.     //    This procedure acts on the currently active tab when the $direction is
  1820.     //    "left" or "right". When the $direction is "up" or "down", this
  1821.     //    procedure acts on the frontmost tab in the bottom or top tab layout
  1822.     //    respectively.
  1823.     //    Once the move has been completed, the tab is made the active tab so
  1824.     //    that it can easily be immediately moved again.
  1825.     //
  1826.  
  1827.     setParent $panel;
  1828.     string $paneLayout = `setParent paneArrangement`;
  1829.  
  1830.     if ($direction == "up")
  1831.     {
  1832.         // Make the bottom tab layout active
  1833.         //
  1834.         paneLayout -edit -activePaneIndex 2 paneArrangement;
  1835.     }
  1836.     else if ($direction == "down")
  1837.     {
  1838.         // Make the top tab layout active
  1839.         //
  1840.         paneLayout -edit -activePaneIndex 1 paneArrangement;
  1841.     }
  1842.  
  1843.     // Determine what tab layout is currently active, and which tab layout the
  1844.     // tab is being moved to.
  1845.     //
  1846.     int     $activePaneIndex = activePaneIndex($panel);
  1847.     string     $activeTabLayout;
  1848.  
  1849.     if ($activePaneIndex == 1) 
  1850.     {
  1851.         $activeTabLayout = "firstPaneTabs";
  1852.     }
  1853.     else 
  1854.     {
  1855.         $activeTabLayout = "secondPaneTabs";
  1856.     }
  1857.  
  1858.     int     $activeTabIndex = activeTabIndex($panel);
  1859.  
  1860.     if (($direction == "left") || ($direction == "right"))
  1861.     {
  1862.         int $numTabs = `tabLayout -query -numberOfChildren $activeTabLayout`;
  1863.         int $targetTabIndex;
  1864.  
  1865.         if (($direction == "left") && ($activeTabIndex > 1))
  1866.         {
  1867.             $targetTabIndex = $activeTabIndex - 1;
  1868.             tabLayout
  1869.                 -edit
  1870.                 -moveTab $activeTabIndex $targetTabIndex
  1871.                 $activeTabLayout;
  1872.  
  1873.             // Bring the target tab to the front
  1874.             //
  1875.             tabLayout
  1876.                 -edit
  1877.                 -selectTabIndex $targetTabIndex
  1878.                 $activeTabLayout;
  1879.  
  1880.             // Update the tab layout option vars now that a tab has been moved
  1881.             //
  1882.             updateTabLayoutOptionVar($panel, $activeTabLayout);
  1883.         }
  1884.         else if (($direction == "right") && ($activeTabIndex < $numTabs))
  1885.         {
  1886.             $targetTabIndex = $activeTabIndex + 1;
  1887.             tabLayout
  1888.                 -edit
  1889.                 -moveTab $activeTabIndex $targetTabIndex
  1890.                 $activeTabLayout;
  1891.  
  1892.             // Bring the target tab to the front
  1893.             //
  1894.             tabLayout
  1895.                 -edit
  1896.                 -selectTabIndex $targetTabIndex
  1897.                 $activeTabLayout;
  1898.  
  1899.             // Update the tab layout option vars now that a tab has been moved
  1900.             //
  1901.             updateTabLayoutOptionVar($panel, $activeTabLayout);
  1902.         }
  1903.     }
  1904.     else
  1905.     {
  1906.         string     $activeTab             = activeTab($panel);
  1907.     
  1908.         string     $targetTabLabel     = activeTabLabel($panel);
  1909.         int     $targetPaneIndex;
  1910.         string     $targetTabLayout;
  1911.  
  1912.         if ($activePaneIndex == 1) 
  1913.         {
  1914.             $targetTabLayout = "secondPaneTabs";
  1915.             $targetPaneIndex = 2;
  1916.         }
  1917.         else 
  1918.         {
  1919.             $targetTabLayout = "firstPaneTabs";
  1920.             $targetPaneIndex = 1;
  1921.         }
  1922.  
  1923.         string $recreatedTab;
  1924.  
  1925.         // Determine what kind of tab the current tab is (disk/graph/scene)
  1926.         //
  1927.         if (isDiskTab($activeTab))
  1928.         {
  1929.             string $libraryUI;
  1930.             $libraryUI = lookupComponentName($activeTab);
  1931.  
  1932.             // Store the information needed to recreate the tab into an 
  1933.             // optionVar
  1934.             //
  1935.             string $tabOptionVar = lookupTabOptionVar($activeTab);
  1936.             updateTabOptionVar($tabOptionVar, $activeTab);
  1937.  
  1938.             // Delete the libraryUI and the active tab.
  1939.             //
  1940.             unregisterTab($activeTab);
  1941.             libraryUIDelete(
  1942.                 $libraryUI, 
  1943.                 false); // don't delete the visors
  1944.             deleteUI $activeTab;
  1945.  
  1946.             // Recreate the libraryUI in the target tab.
  1947.             //
  1948.             $recreatedTab = recreateDiskTab(
  1949.                 $panel, 
  1950.                 $targetTabLayout,
  1951.                 $tabOptionVar,
  1952.                 true /* reuse editors */);
  1953.             
  1954.         }
  1955.         else if (isGraphTab($activeTab))
  1956.         {
  1957.             int $protected = (lookupTabType($activeTab) == "protected graph");
  1958.             string $graphUI;
  1959.             $graphUI = lookupComponentName($activeTab);
  1960.  
  1961.             // Store the information needed to recreate the tab into an 
  1962.             // optionVar
  1963.             //
  1964.             string $tabOptionVar = lookupTabOptionVar($activeTab);
  1965.             updateTabOptionVar($tabOptionVar, $activeTab);
  1966.  
  1967.             // Delete the libraryUI and the active tab.
  1968.             //
  1969.             unregisterTab($activeTab);
  1970.             graphUIDelete(
  1971.                 $graphUI, 
  1972.                 false); // don't delete the hypershade
  1973.             deleteUI $activeTab;
  1974.  
  1975.             // Recreate the libraryUI in the target tab.
  1976.             //
  1977.             $recreatedTab = recreateGraphTab(
  1978.                 $panel, 
  1979.                 $targetTabLayout,
  1980.                 $tabOptionVar,
  1981.                 true, /* reuse editors */
  1982.                 $protected);
  1983.         }
  1984.         else if (isSceneTab($activeTab))
  1985.         {
  1986.             string $collectionUI;
  1987.             $collectionUI = lookupComponentName($activeTab);
  1988.  
  1989.             // Store the information needed to recreate the tab into an 
  1990.             // optionVar
  1991.             //
  1992.             string $tabOptionVar = lookupTabOptionVar($activeTab);
  1993.             updateTabOptionVar($tabOptionVar, $activeTab);
  1994.  
  1995.             // Delete the collectionUI and the active tab.
  1996.             //
  1997.             unregisterTab($activeTab);
  1998.             collectionUIDelete(
  1999.                 $collectionUI, 
  2000.                 false); // don't delete the hypershade
  2001.             deleteUI $activeTab;
  2002.  
  2003.             // Recreate the collectionUI in the target tab.
  2004.             //
  2005.             $recreatedTab = recreateSceneTab(
  2006.                 $panel, 
  2007.                 $targetTabLayout,
  2008.                 $tabOptionVar,
  2009.                 true /* reuse editors */);
  2010.         }
  2011.  
  2012.         // Bring the target tab to the front
  2013.         //
  2014.         tabLayout
  2015.             -edit
  2016.             -selectTab $recreatedTab
  2017.             $targetTabLayout;
  2018.         
  2019.         // Give the target tab layout focus so the user can move the tab
  2020.         // again without having to reselect it.
  2021.         //
  2022.         paneLayout -edit -activePaneIndex $targetPaneIndex paneArrangement;
  2023.  
  2024.         // Update the tab layout option vars now that a tab has been moved
  2025.         //
  2026.         updateTabLayoutOptionVar($panel, $activeTabLayout);
  2027.         updateTabLayoutOptionVar($panel, $targetTabLayout);
  2028.     }
  2029. }
  2030.  
  2031. proc removeTab(
  2032.     string $tab)
  2033. {
  2034.     //
  2035.     // Description:
  2036.     //    This procedure removes the specified tab from the hypershade panel.
  2037.     //
  2038.  
  2039.     // Delete the option var which describes this tab, so that it won't come
  2040.     // back the next time the user runs Maya
  2041.     //
  2042.     deleteTabOptionVar($tab);
  2043.  
  2044.     // Determine what kind of tab the current tab is (disk/graph/scene)
  2045.     //
  2046.     if (isDiskTab($tab))
  2047.     {
  2048.         string $libraryUI;
  2049.         $libraryUI = lookupComponentName($tab);
  2050.  
  2051.         // Delete the libraryUI and the active tab.
  2052.         //
  2053.         unregisterTab($tab);
  2054.         libraryUIDelete(
  2055.             $libraryUI, 
  2056.             true); // delete the visors
  2057.         deleteUI $tab;
  2058.     }
  2059.     else if (isGraphTab($tab))
  2060.     {
  2061.         string $graphUI;
  2062.         $graphUI = lookupComponentName($tab);
  2063.  
  2064.         // Delete the graphUI and the active tab.
  2065.         //
  2066.         unregisterTab($tab);
  2067.         graphUIDelete(
  2068.             $graphUI, 
  2069.             true); // delete the hypershade
  2070.         deleteUI $tab;
  2071.     }
  2072.     else if (isSceneTab($tab))
  2073.     {
  2074.         string $collectionUI;
  2075.         $collectionUI = lookupComponentName($tab);
  2076.  
  2077.         // Delete the collectionUI and the active tab.
  2078.         //
  2079.         unregisterTab($tab);
  2080.         collectionUIDelete(
  2081.             $collectionUI, 
  2082.             true); // delete the hypershade
  2083.         deleteUI $tab;
  2084.     }
  2085. }
  2086.  
  2087. proc removeActiveTab(
  2088.     string $panel)
  2089. {
  2090.     //
  2091.     // Description:
  2092.     //    This procedure removes the active tab from the hypershade panel.
  2093.     //
  2094.  
  2095.     setParent $panel;
  2096.     string $paneLayout = `setParent paneArrangement`;
  2097.  
  2098.     // Determine what tab layout is currently active.
  2099.     //
  2100.     string $tabLayout;
  2101.     $tabLayout = activeTabLayout($panel);
  2102.  
  2103.     string     $activeTab = activeTab($panel);
  2104.  
  2105.     if (`lookupTabType($activeTab)` == "protected graph")
  2106.     {
  2107.         // The active tab is marked as a protected graph, which means we don't
  2108.         // want to allow it to be deleted or moved between tab layouts.
  2109.         //
  2110.         return;
  2111.     }
  2112.  
  2113.     removeTab($activeTab);
  2114.  
  2115.     // Delete the option var which describes this tab, so that it won't come
  2116.     // back the next time the user runs Maya
  2117.     //
  2118.     deleteTabOptionVar($activeTab);
  2119.  
  2120.     // Determine what kind of tab the current tab is (disk/graph/scene)
  2121.     //
  2122.     if (isDiskTab($activeTab))
  2123.     {
  2124.         string $libraryUI;
  2125.         $libraryUI = lookupComponentName($activeTab);
  2126.  
  2127.         // Delete the libraryUI and the active tab.
  2128.         //
  2129.         unregisterTab($activeTab);
  2130.         libraryUIDelete(
  2131.             $libraryUI, 
  2132.             true); // delete the visors
  2133.         deleteUI $activeTab;
  2134.     }
  2135.     else if (isGraphTab($activeTab))
  2136.     {
  2137.         string $graphUI;
  2138.         $graphUI = lookupComponentName($activeTab);
  2139.  
  2140.         // Delete the graphUI and the active tab.
  2141.         //
  2142.         unregisterTab($activeTab);
  2143.         graphUIDelete(
  2144.             $graphUI, 
  2145.             true); // delete the hypershade
  2146.         deleteUI $activeTab;
  2147.     }
  2148.     else if (isSceneTab($activeTab))
  2149.     {
  2150.         string $collectionUI;
  2151.         $collectionUI = lookupComponentName($activeTab);
  2152.  
  2153.         // Delete the collectionUI and the active tab.
  2154.         //
  2155.         unregisterTab($activeTab);
  2156.         collectionUIDelete(
  2157.             $collectionUI, 
  2158.             true); // delete the hypershade
  2159.         deleteUI $activeTab;
  2160.     }
  2161.  
  2162.     // Update the tab layout option var now that the tab has been deleted
  2163.     //
  2164.     updateTabLayoutOptionVar($panel, $tabLayout);
  2165. }
  2166.  
  2167. proc refreshToolbar(
  2168.     string $panel)
  2169. {
  2170.     setParent $panel;
  2171.     setParent toolbarForm;
  2172.  
  2173.     string $activeTab = activeTab($panel);
  2174.  
  2175.     // Enable the Clear Graph and Rearrange Graph buttons only if a graph tab
  2176.     // (work area) is visible.
  2177.     //
  2178.     int $enable;
  2179.     $enable = isGraphTabVisible($panel);
  2180.  
  2181.     iconTextButton
  2182.         -edit
  2183.         -enable $enable
  2184.         clearGraphButton;
  2185.  
  2186.     iconTextButton
  2187.         -edit
  2188.         -enable $enable
  2189.         rearrangeGraphButton;
  2190.  
  2191.     // The radio buttons which indicate which tab sections are shown need
  2192.     // to be kept in sync with the optionVar which stores that information.
  2193.     //
  2194.     if (`optionVar -query hyperShadePanelTabSectionsShown` 
  2195.             == "showTopTabsOnly")
  2196.     {
  2197.         iconTextRadioButton
  2198.             -edit
  2199.             -select
  2200.             showTopTabsOnlyButton;
  2201.     }
  2202.     else if (
  2203.         `optionVar -query hyperShadePanelTabSectionsShown` 
  2204.             == "showBottomTabsOnly")
  2205.     {
  2206.         iconTextRadioButton
  2207.             -edit
  2208.             -select
  2209.             showBottomTabsOnlyButton;
  2210.     }
  2211.     else
  2212.     {
  2213.         iconTextRadioButton
  2214.             -edit
  2215.             -select
  2216.             showTopAndBottomTabsButton;
  2217.     }
  2218. }
  2219.  
  2220. proc refreshFileMenu(
  2221.     string $panel)
  2222. {
  2223.     //
  2224.     // Description:
  2225.     //    This procedure is called after a change is made which would require the
  2226.     //    hypershade panel File menu to be updated to reflect a new state of the 
  2227.     //    UI. This procedure is not invoked automatically when a change which 
  2228.     //    affects the menus occurs, it must be explicitly called.
  2229.     //    This procedure refreshes the File menu as appropriate considering the
  2230.     //    current state of the UI.
  2231.     //
  2232.  
  2233.     // Remember the current parent so we can revert to it when we're done here.
  2234.     //
  2235.     string $oldParent = `setParent -query`;
  2236.     string $oldMenuParent = `setParent -menu -query`;
  2237.  
  2238.     setParent $panel;
  2239.  
  2240.     string $menuPrefix = "hyperShadePanelMenu";
  2241.     string $menu = ($menuPrefix + "FileMenu");
  2242.  
  2243.     if (`menu -exists $menu`)
  2244.     {
  2245.         setParent -menu $menu;
  2246.  
  2247.         // Update the import textures with placement checkbox
  2248.         //
  2249.         menuItem
  2250.             -edit
  2251.             -checkBox 
  2252.                 `optionVar -query createTexturesWithPlacement`
  2253.             importIncludePlacementItem;
  2254.     }
  2255.  
  2256.     // Revert to the original parent.
  2257.     //
  2258.     if ($oldParent != "NONE") setParent $oldParent;
  2259.     if ($oldMenuParent != "NONE") setParent -menu $oldMenuParent;
  2260. }
  2261.  
  2262. proc refreshCreateMenu(
  2263.     string $panel)
  2264. {
  2265.     //
  2266.     // Description:
  2267.     //    This procedure is called after a change is made which would require the
  2268.     //    hypershade panel Create menu to be updated to reflect a new state of 
  2269.     //    the UI. For example, when the user changes the state of the With
  2270.     //    Shading Group checkbox in the create render node dialog, the menu 
  2271.     //    needs to be refreshed so that the menu item which reflects the state of
  2272.     //    that checkbox is kept in sync. This procedure is not invoked 
  2273.     //    automatically when a change which affects the menus occurs, it must be
  2274.     //    explicitly called.
  2275.     //    This procedure refreshes the Create menu as appropriate considering the
  2276.     //    current state of the UI.
  2277.     //
  2278.  
  2279.     // Remember the current parent so we can revert to it when we're done here.
  2280.     //
  2281.     string $oldParent = `setParent -query`;
  2282.     string $oldMenuParent = `setParent -menu -query`;
  2283.  
  2284.     setParent $panel;
  2285.  
  2286.     string $menuPrefix = "hyperShadePanelMenu";
  2287.     string $menu = ($menuPrefix + "CreateMenu");
  2288.  
  2289.     // Since the Create menu is built each time it is opened, the menu
  2290.     // items it contains may not exist if it has not yet been opened.
  2291.     // We will only try to update the menu if the menu items actually 
  2292.     // exist.
  2293.     //
  2294.     if (    (`menu -exists $menu`)
  2295.         &&    (`menu -query -numberOfItems $menu` > 0))
  2296.     {
  2297.         setParent -menu $menu;
  2298.  
  2299.         // Update the create textures with placement checkbox
  2300.         //
  2301.         menuItem
  2302.             -edit
  2303.             -checkBox 
  2304.                 `optionVar -query createTexturesWithPlacement`
  2305.             createIncludePlacementItem;
  2306.  
  2307.         // Update the normal/projection/stencil radiobuttons
  2308.         //
  2309.         menuItem 
  2310.             -edit
  2311.             -radioButton 
  2312.                 (`optionVar -query create2dTextureType` == "normal")
  2313.             textureAsNormalItem;
  2314.         menuItem 
  2315.             -edit
  2316.             -radioButton 
  2317.                 (`optionVar -query create2dTextureType` == "projection")
  2318.             textureAsProjectionItem;
  2319.         menuItem 
  2320.             -edit
  2321.             -radioButton 
  2322.                 (`optionVar -query create2dTextureType` == "stencil")
  2323.             textureAsStencilItem;
  2324.  
  2325.         // Update the create materials with shading groups checkbox
  2326.         //
  2327.         menuItem
  2328.             -edit
  2329.             -checkBox 
  2330.                 `optionVar -query createMaterialsWithShadingGroup`
  2331.             includeShadingGroupItem;
  2332.     }
  2333.  
  2334.     // Revert to the original parent.
  2335.     //
  2336.     if ($oldParent != "NONE") setParent $oldParent;
  2337.     if ($oldMenuParent != "NONE") setParent -menu $oldMenuParent;
  2338. }
  2339.  
  2340. proc refreshTabsMenu(
  2341.     string $panel)
  2342. {
  2343.     //
  2344.     // Description:
  2345.     //    This procedure is called after a change is made which would require the
  2346.     //    hypershade panel Tabs menu to be updated to reflect a new state of the 
  2347.     //    UI. For example, when the user presses one of the toolbar buttons which
  2348.     //    changes which tab sections are shown, the menus need to be refreshed so 
  2349.     //    that the menu items which indicate which tab sections are shown are
  2350.     //    properly updated. 
  2351.     //    This procedure is not invoked automatically when a change which affects 
  2352.     //    the menus occurs, it must be explicitly called.
  2353.     //    This procedure refreshes the Tabs menu as appropriate considering the
  2354.     //    current state of the UI.
  2355.     //
  2356.  
  2357.     // Remember the current parent so we can revert to it when we're done here.
  2358.     //
  2359.     string $oldParent = `setParent -query`;
  2360.     string $oldMenuParent = `setParent -menu -query`;
  2361.  
  2362.     setParent $panel;
  2363.  
  2364.     string $menuPrefix = "hyperShadePanelMenu";
  2365.     string $menu = ($menuPrefix + "TabsMenu");
  2366.  
  2367.     if (`menu -exists $menu`)
  2368.     {
  2369.         setParent -menu $menu;
  2370.  
  2371.         // Move Tab Up and Move Tab Down should be enabled if and only if both
  2372.         // tab sections are shown.
  2373.         //
  2374.         menuItem
  2375.             -edit
  2376.             -enable
  2377.                 (`optionVar -query hyperShadePanelTabSectionsShown`
  2378.                     == "showTopAndBottomTabs")
  2379.             tabsMoveTabUpItem;
  2380.         menuItem
  2381.             -edit
  2382.             -enable
  2383.                 (`optionVar -query hyperShadePanelTabSectionsShown`
  2384.                     == "showTopAndBottomTabs")
  2385.             tabsMoveTabDownItem;
  2386.  
  2387.         // The radio buttons which indicate which tab sections are shown need
  2388.         // to be kept in sync with the optionVar which stores that information.
  2389.         //
  2390.         menuItem 
  2391.             -edit
  2392.             -radioButton 
  2393.                 (`optionVar -query hyperShadePanelTabSectionsShown` 
  2394.                     == "showTopTabsOnly")
  2395.             tabsShowTopTabsOnlyItem;
  2396.         menuItem 
  2397.             -edit
  2398.             -radioButton 
  2399.                 (`optionVar -query hyperShadePanelTabSectionsShown` 
  2400.                     == "showBottomTabsOnly")
  2401.             tabsShowBottomTabsOnlyItem;
  2402.         menuItem 
  2403.             -edit
  2404.             -radioButton 
  2405.                 (`optionVar -query hyperShadePanelTabSectionsShown` 
  2406.                     == "showTopAndBottomTabs")
  2407.             tabsShowTopAndBottomTabsItem;
  2408.     }
  2409.  
  2410.     // Revert to the original parent.
  2411.     //
  2412.     if ($oldParent != "NONE") setParent $oldParent;
  2413.     if ($oldMenuParent != "NONE") setParent -menu $oldMenuParent;
  2414. }
  2415.  
  2416. proc refreshGraphMenu(
  2417.     string $panel)
  2418. {
  2419.     //
  2420.     // Description:
  2421.     //    This procedure is called after a change is made which would require the
  2422.     //    hypershade panel Graph menu to be updated to reflect a new state of the 
  2423.     //    UI. For example, when the user selects a new tab, the menus may need 
  2424.     //    to be refreshed so that menu items which apply only if the active tab 
  2425.     //    is a graph tab may be dimmed or undimmed. This procedure is not invoked
  2426.     //    automatically when a change which affects the menus occurs, it must be
  2427.     //    explicitly called.
  2428.     //    This procedure refreshes the Graph menu as appropriate considering the
  2429.     //    current state of the UI.
  2430.     //
  2431.  
  2432.     // Remember the current parent so we can revert to it when we're done here.
  2433.     //
  2434.     string $oldParent = `setParent -query`;
  2435.     string $oldMenuParent = `setParent -menu -query`;
  2436.  
  2437.     setParent $panel;
  2438.  
  2439.     string $menuPrefix = "hyperShadePanelMenu";
  2440.     string $menu = ($menuPrefix + "GraphMenu");
  2441.  
  2442.     if (`menu -exists $menu`)
  2443.     {
  2444.         setParent -menu $menu;
  2445.  
  2446.         // Enable some graph menu items only if a graph tab (work area) is 
  2447.         // visible
  2448.         //
  2449.         int $enable;
  2450.         $enable = isGraphTabVisible($panel);
  2451.  
  2452.         menuItem 
  2453.             -edit
  2454.             -enable $enable
  2455.             clearGraphItem;
  2456.         menuItem 
  2457.             -edit
  2458.             -enable $enable
  2459.             rearrangeGraphItem;
  2460.         menuItem 
  2461.             -edit
  2462.             -enable $enable
  2463.             showPreviousGraphItem;
  2464.         menuItem 
  2465.             -edit
  2466.             -enable $enable
  2467.             showNextGraphItem;
  2468.     }
  2469.  
  2470.     // Revert to the original parent.
  2471.     //
  2472.     if ($oldParent != "NONE") setParent $oldParent;
  2473.     if ($oldMenuParent != "NONE") setParent -menu $oldMenuParent;
  2474. }
  2475.  
  2476. global proc hyperShadePanelRefreshMenu(
  2477.     string $panel,
  2478.     string $menu)
  2479. {
  2480.     //
  2481.     // Description:
  2482.     //    This procedure is called whenever some procedure outside of this file
  2483.     //    needs to cause one of the hyperShadePanel menus to be updated.
  2484.     //    This procedure calls the appropriate local procedure to update the
  2485.     //    specified menu.
  2486.     //
  2487.  
  2488.     if ($menu == "File")
  2489.     {
  2490.         refreshFileMenu($panel);
  2491.     }
  2492.     else if ($menu == "Create")
  2493.     {
  2494.         refreshCreateMenu($panel);
  2495.     }
  2496.     else if ($menu == "Tabs")
  2497.     {
  2498.         refreshTabsMenu($panel);
  2499.     }
  2500.     else if ($menu == "Graph")
  2501.     {
  2502.         refreshGraphMenu($panel);
  2503.     }
  2504.     else 
  2505.     {
  2506.         // Somebody is trying to refresh a menu for which there is no refresh
  2507.         // procedure.
  2508.         //
  2509.         warning("Trying to refresh menu for which no refresh procedure exists");
  2510.     }
  2511. }
  2512.  
  2513. global proc hyperShadePanelRefreshCreateBar(
  2514.     string $panel)
  2515. {
  2516.     //
  2517.     // Description:
  2518.     //    This procedure is called when some procedure outside of this file has
  2519.     //    made a change to the state of Maya which requires the create bar
  2520.     //    contained within the hyperShadePanel to be updated.
  2521.     //    This procedure determines the name of the create bar and updates it.
  2522.     //
  2523.  
  2524.     string $renderCreateBarUI = renderCreateBarUIName($panel);
  2525.     renderCreateBarUIRefresh($renderCreateBarUI);
  2526. }
  2527.  
  2528. global proc hyperShadePanelSetActiveTabLayout(
  2529.     string $panel,
  2530.     string $tabLayout)
  2531. {
  2532.     //
  2533.     // Description:
  2534.     //    This procedure is invoked when the focus command on the hyper
  2535.     //  shade is run; this will occur when the mouse button is released
  2536.     //  in the view.
  2537.     //
  2538.  
  2539.     setParent paneArrangement;
  2540.  
  2541.     if ($tabLayout == "firstPaneTabs")
  2542.     {
  2543.         paneLayout -e -activePaneIndex 1 paneArrangement;
  2544.     }
  2545.     else if ($tabLayout == "secondPaneTabs")
  2546.     {
  2547.         if (`paneLayout -query -configuration paneArrangement` == "single")
  2548.         {
  2549.             paneLayout -e -activePaneIndex 1 paneArrangement;
  2550.         }
  2551.         else
  2552.         {
  2553.             paneLayout -e -activePaneIndex 2 paneArrangement;
  2554.         }
  2555.     }
  2556.  
  2557.     refreshToolbar($panel);
  2558.     refreshGraphMenu($panel);
  2559. }
  2560.  
  2561. proc int topTabsShown(
  2562.     string $panel)
  2563. {
  2564.     //
  2565.     // Description:
  2566.     //    This procedure determines whether the top tab section of the hypershade
  2567.     //    panel is being displayed.
  2568.     //
  2569.     // Returns: 
  2570.     //    True if the top tab section is being displayed, false otherwise.
  2571.     //
  2572.     string $tabSectionsShown = 
  2573.         `optionVar -query hyperShadePanelTabSectionsShown`;
  2574.     
  2575.     return (
  2576.             ($tabSectionsShown == "showTopTabsOnly")
  2577.         ||    ($tabSectionsShown == "showTopAndBottomTabs"));
  2578. }
  2579.  
  2580. proc int bottomTabsShown(
  2581.     string $panel)
  2582. {
  2583.     //
  2584.     // Description:
  2585.     //    This procedure determines whether the bottom tab section of the 
  2586.     //    hypershade panel is being displayed.
  2587.     //
  2588.     // Returns: 
  2589.     //    True if the bottom tab section is being displayed, false otherwise.
  2590.     //
  2591.     string $tabSectionsShown = 
  2592.         `optionVar -query hyperShadePanelTabSectionsShown`;
  2593.     
  2594.     return (
  2595.             ($tabSectionsShown == "showBottomTabsOnly")
  2596.         ||    ($tabSectionsShown == "showTopAndBottomTabs"));
  2597. }
  2598.  
  2599. proc showTopTabsOnly(
  2600.     string $panel)
  2601. {
  2602.     //
  2603.     // Description:
  2604.     //    This procedure causes the hypershade to reconfigure so that only the
  2605.     //    top tab section is visible.
  2606.     //
  2607.  
  2608.     setParent $panel;
  2609.     paneLayout
  2610.         -edit
  2611.         -configuration "single"
  2612.         -setPane firstPaneTabs 1
  2613.         -activePaneIndex 1
  2614.         paneArrangement;
  2615.  
  2616.     // Update the option var which remembers which tab sections are shown
  2617.     //
  2618.     optionVar 
  2619.         -stringValue 
  2620.             hyperShadePanelTabSectionsShown 
  2621.             "showTopTabsOnly";
  2622.  
  2623.     // Update the menus which are affected by this change
  2624.     //
  2625.     refreshTabsMenu($panel);
  2626.     refreshToolbar($panel);
  2627. }
  2628.  
  2629. proc showBottomTabsOnly(
  2630.     string $panel)
  2631. {
  2632.     //
  2633.     // Description:
  2634.     //    This procedure causes the hypershade to reconfigure so that only the
  2635.     //    bottom tab section is visible.
  2636.     //
  2637.  
  2638.     setParent $panel;
  2639.     paneLayout
  2640.         -edit
  2641.         -configuration "single"
  2642.         -setPane secondPaneTabs 1
  2643.         -activePaneIndex 1
  2644.         paneArrangement;
  2645.  
  2646.     // Update the option var which remembers which tab sections are shown
  2647.     //
  2648.     optionVar 
  2649.         -stringValue 
  2650.             hyperShadePanelTabSectionsShown 
  2651.             "showBottomTabsOnly";
  2652.  
  2653.     // Update the menus which are affected by this change
  2654.     //
  2655.     refreshTabsMenu($panel);
  2656.     refreshToolbar($panel);
  2657. }
  2658.  
  2659. proc showTopAndBottomTabs(
  2660.     string $panel)
  2661. {
  2662.     //
  2663.     // Description:
  2664.     //    This procedure causes the hypershade to reconfigure so that both the
  2665.     //    top and bottom tab sections are visible.
  2666.     //
  2667.  
  2668.     setParent $panel;
  2669.  
  2670.     int $activePaneIndex;
  2671.  
  2672.     // Determine whether it is the top or the bottom which is currently
  2673.     // visible, and thus which pane should be active once both are displayed.
  2674.     //
  2675.     if (topTabsShown($panel))
  2676.     {
  2677.         $activePaneIndex = 1;
  2678.     }
  2679.     else
  2680.     {
  2681.         $activePaneIndex = 2;
  2682.     }
  2683.  
  2684.     paneLayout
  2685.         -edit
  2686.         -configuration "horizontal2" // stacked
  2687.         -setPane firstPaneTabs 1
  2688.         -setPane secondPaneTabs 2
  2689.         -activePaneIndex 1
  2690.         paneArrangement;
  2691.  
  2692.     // Update the option var which remembers which tab sections are shown
  2693.     //
  2694.     optionVar 
  2695.         -stringValue 
  2696.             hyperShadePanelTabSectionsShown 
  2697.             "showTopAndBottomTabs";
  2698.  
  2699.     // Update the menus which are affected by this change
  2700.     //
  2701.     refreshTabsMenu($panel);
  2702.     refreshToolbar($panel);
  2703. }
  2704.  
  2705. proc selectTab(
  2706.     string $panel,
  2707.     string $tab)
  2708. {
  2709.     //
  2710.     // Description:
  2711.     //    This procedure selects the specified tab, bringing it to the front of
  2712.     //    its tab layout and making the pane in which it resides the active pane.
  2713.     //
  2714.  
  2715.     // Remember the current parent so we can revert to it when we're done here.
  2716.     //
  2717.     string $oldParent = `setParent -query`;
  2718.     string $oldMenuParent = `setParent -menu -query`;
  2719.  
  2720.     setParent $tab;
  2721.     string $tabLayout = `setParent ..`;
  2722.     string $tabPathTokens[];
  2723.  
  2724.     tokenize($tab, "|", $tabPathTokens);
  2725.  
  2726.     string $tabShortName = $tabPathTokens[size($tabPathTokens) - 1];
  2727.     string $tabLayoutShortName = $tabPathTokens[size($tabPathTokens) - 2];
  2728.  
  2729.     // If the tab to be selected is in a tab section which is not currently
  2730.     // shown, we will switch to show both tab sections so the user can see the
  2731.     // tab.
  2732.     //
  2733.     if (
  2734.             (    ($tabLayoutShortName == "firstPaneTabs") 
  2735.             &&     (!topTabsShown($panel)))
  2736.         ||    (    ($tabLayoutShortName == "secondPaneTabs") 
  2737.             &&     (!bottomTabsShown($panel))))
  2738.     {
  2739.         showTopAndBottomTabs($panel);
  2740.     }
  2741.  
  2742.     // Select the tab
  2743.     //
  2744.     tabLayout
  2745.         -edit
  2746.         -selectTab $tabShortName
  2747.         $tabLayout;
  2748.  
  2749.     // Set the active pane to the layout which contains the selected tab
  2750.     //
  2751.     setParent $panel;
  2752.  
  2753.     if (
  2754.             ($tabLayoutShortName == "firstPaneTabs")
  2755.         ||    (!topTabsShown($panel)))
  2756.     {
  2757.         paneLayout
  2758.             -edit
  2759.             -activePaneIndex 1
  2760.             paneArrangement;
  2761.     }
  2762.     else
  2763.     {
  2764.         paneLayout
  2765.             -edit
  2766.             -activePaneIndex 2
  2767.             paneArrangement;
  2768.     }
  2769.  
  2770.     // Revert to the original parent.
  2771.     //
  2772.     if ($oldParent != "NONE") setParent $oldParent;
  2773.     if ($oldMenuParent != "NONE") setParent -menu $oldMenuParent;
  2774. }
  2775.  
  2776. proc revertToDefaultTabs(
  2777.     string $panel)
  2778. {
  2779.     //
  2780.     // Description:
  2781.     //    This procedure removes all tabs from the hypershade panel and creates
  2782.     //    the default set of tabs. 
  2783.     //
  2784.  
  2785.     setParent $panel;
  2786.     string $mainForm = `setParent mainForm`;
  2787.     formLayout -edit -manage false $mainForm;
  2788.  
  2789.     // Delete all tabs
  2790.     //
  2791.     int $i;
  2792.     string $tabArray[];
  2793.     string $tab;
  2794.  
  2795.     $tabArray = `tabLayout -query -childArray firstPaneTabs`;
  2796.  
  2797.     for ($i = 0; $i < size($tabArray); $i++)
  2798.     {
  2799.         setParent $panel;
  2800.         $tab = `setParent $tabArray[$i]`;
  2801.         removeTab($tab);
  2802.     }
  2803.  
  2804.     $tabArray = `tabLayout -query -childArray secondPaneTabs`;
  2805.  
  2806.     for ($i = 0; $i < size($tabArray); $i++)
  2807.     {
  2808.         setParent $panel;
  2809.         $tab = `setParent $tabArray[$i]`;
  2810.         removeTab($tab);
  2811.     }
  2812.  
  2813.     formLayout -edit -manage true $mainForm;
  2814.  
  2815.     // Create the default tabs
  2816.     //
  2817.     createSceneTab(
  2818.         $panel,
  2819.         "firstPaneTabs",
  2820.         "Materials",
  2821.         "MaterialsAndShaderGlow");
  2822.  
  2823.     createSceneTab(
  2824.         $panel,
  2825.         "firstPaneTabs",
  2826.         "Textures",
  2827.         "Textures");
  2828.  
  2829.     createSceneTab(
  2830.         $panel,
  2831.         "firstPaneTabs",
  2832.         "Utilities",
  2833.         "Utilities");
  2834.  
  2835.     createSceneTab(
  2836.         $panel,
  2837.         "firstPaneTabs",
  2838.         "Lights",
  2839.         "LightsAndOpticalFX");
  2840.  
  2841.     createSceneTab(
  2842.         $panel,
  2843.         "firstPaneTabs",
  2844.         "Cameras",
  2845.         "Cameras");
  2846.  
  2847.     createSceneTab(
  2848.         $panel,
  2849.         "firstPaneTabs",
  2850.         "Bake Sets",
  2851.         "BakeSets");
  2852.  
  2853.     string $projectsDir = `internalVar -userWorkspaceDir`;
  2854.  
  2855.     createDiskTab(
  2856.         $panel,
  2857.         "firstPaneTabs",
  2858.         "Projects",
  2859.         $projectsDir);
  2860.  
  2861.     createGraphTab(
  2862.         $panel,
  2863.         "secondPaneTabs",
  2864.         "Work Area",
  2865.         true);
  2866.  
  2867.     string $shaderLibraryDir = `getenv MAYA_SHADER_LIBRARY_PATH`;
  2868.  
  2869.     if ($shaderLibraryDir != "")
  2870.     {
  2871.         optionVar -intValue hyperShadeShaderLibraryTabCreated 1;
  2872.         createDiskTab(
  2873.             $panel,
  2874.             "secondPaneTabs",
  2875.             "Shader Library",
  2876.             $shaderLibraryDir);
  2877.     }
  2878.  
  2879.     // If this is the first time the user has opened hypershade since 3.0, and
  2880.     // they have custom disk folders defined in their userPrefs, we will create
  2881.     // a tab for each of those custom disk folders.
  2882.     //
  2883.     if (    (!`optionVar -exists customFoldersConvertedForHypershade`)
  2884.         &&    (`optionVar -exists visorCustomDiskFolders`))
  2885.     {
  2886.         // Get from an optionVar the list of directories for which custom disk 
  2887.         // folders were created. Create a disk tab for each.
  2888.         //
  2889.         int     $i;
  2890.         string     $customFolderNameArray[];
  2891.  
  2892.         $customFolderNameArray = `optionVar -query visorCustomDiskFolders`;
  2893.  
  2894.         for ($i = 0; $i < size($customFolderNameArray); $i++)
  2895.         {
  2896.             // Tokenize the path stored in $customFolderNameArray[$i] so that
  2897.             // we can have a shorter name for the tab.
  2898.             //
  2899.             string $pathTokens[];
  2900.             tokenize $customFolderNameArray[$i] "/" $pathTokens;
  2901.  
  2902.             createDiskTab(
  2903.                 $panel,
  2904.                 "secondPaneTabs",
  2905.                 $pathTokens[size($pathTokens) - 1],
  2906.                 $customFolderNameArray[$i]);
  2907.         }
  2908.  
  2909.         if (`optionVar -exists customFoldersConvertedForVisor`)
  2910.         {
  2911.             // These custom disk folders have also already been added to Visor.
  2912.             // This means that we no longer need to keep the
  2913.             // visorCustomDiskFolders optionVar around.
  2914.             // We also don't need the customFoldersConvertedForVisor optionVar
  2915.             // anymore because it has served its purpose.
  2916.             //
  2917.             optionVar -remove visorCustomDiskFolders;
  2918.             optionVar -remove customFoldersConvertedForVisor;
  2919.         }
  2920.         else
  2921.         {
  2922.             // Set an optionVar to indicate that these custom disk folders have
  2923.             // already been added to Hypershade
  2924.             //
  2925.             optionVar -intValue customFoldersConvertedForHypershade true;
  2926.         }
  2927.     }
  2928.  
  2929.     // Update the tab layout option vars now that the tabs have been reverted
  2930.     //
  2931.     updateTabLayoutOptionVar($panel, "firstPaneTabs");
  2932.     updateTabLayoutOptionVar($panel, "secondPaneTabs");
  2933.  
  2934.     // Now that we have created all the tabs we need, we delete any option vars
  2935.     // which describe tabs that did not get used.
  2936.     //
  2937.     deleteUnusedTabOptionVars($panel);
  2938. }
  2939.  
  2940. proc initTabs(string $panel)
  2941. {
  2942.     //
  2943.     // Description:
  2944.     //    This procedure is called the first time the hypershade panel is opened
  2945.     //    during a Maya session.
  2946.     //    This procedure uses the optionVars which describe the contents of the
  2947.     //    hypershade panel tab layouts and tabs in order to recreate the
  2948.     //    hypershade panel as it appeared when it was last open.
  2949.     //    If no such optionVars exist, this procedure causes the default tabs to
  2950.     //    be created.
  2951.     //
  2952.  
  2953.     // Clear the lookup table because we are creating a fresh visor panel
  2954.     //
  2955.     global string $gHyperShadePanelLookupTable[];
  2956.     lookupTableReset($gHyperShadePanelLookupTable);
  2957.  
  2958.     // In Maya 4.0, trying to reuse editors was problematic because the
  2959.     // contents of the editor would be badly positioned when hypershade was
  2960.     // reopened with a reused editor. So we will not reuse editors for 4.0, but
  2961.     // may do so in the future.
  2962.     //
  2963.     int $reuseEditors = false;
  2964.  
  2965.     if (!`optionVar -exists hyperShadeFirstPaneTabs`)
  2966.     {
  2967.         // The option vars which should contain the names of the option vars
  2968.         // describing the tabs in the tab layouts do not exist.
  2969.         // This indicates that this is the first time the user is using
  2970.         // this version of Maya, or that their prefs have been deleted.
  2971.         // In this situation we want to fill the shader editor with what we
  2972.         // consider to be useful and appropriate default tabs.
  2973.         //
  2974.         revertToDefaultTabs($panel);
  2975.         return;
  2976.     }
  2977.  
  2978.     // If we get to here, it means the user already has option vars in their
  2979.     // prefs to describe the tabs they expect to see in their shader editor.
  2980.     // 
  2981.     // We will read ther user's preferred set of tabs from optionVars and 
  2982.     // create them.
  2983.     //
  2984.     int $i;
  2985.  
  2986.     string $firstPaneTabVars[];
  2987.     $firstPaneTabVars = `optionVar -query hyperShadeFirstPaneTabs`;
  2988.  
  2989.     setParent $panel;
  2990.     
  2991.     for ($i = 0; $i < size($firstPaneTabVars); $i++)
  2992.     {
  2993.         recreateTab(
  2994.             $panel,
  2995.             "firstPaneTabs",
  2996.             $firstPaneTabVars[$i],
  2997.             $reuseEditors);
  2998.     }
  2999.  
  3000.     string $secondPaneTabVars[];
  3001.     $secondPaneTabVars = `optionVar -query hyperShadeSecondPaneTabs`;
  3002.  
  3003.     setParent $panel;
  3004.     
  3005.     for ($i = 0; $i < size($secondPaneTabVars); $i++)
  3006.     {
  3007.         recreateTab(
  3008.             $panel,
  3009.             "secondPaneTabs",
  3010.             $secondPaneTabVars[$i],
  3011.             $reuseEditors);
  3012.     }
  3013.  
  3014.     // If the shader library has never been added as a hypershade tab, we will
  3015.     // check to see if it exists and add it if it does.
  3016.     // In this way, the user will always get a shader library tab created for
  3017.     // them when they install the shader library, but if they delete that tab
  3018.     // it won't come back unless they revert to default tabs or delete their
  3019.     // userPrefs.
  3020.     //
  3021.     if (!`optionVar -exists hyperShadeShaderLibraryTabCreated`)
  3022.     {
  3023.         string $shaderLibraryDir = `getenv MAYA_SHADER_LIBRARY_PATH`;
  3024.  
  3025.         if ($shaderLibraryDir != "")
  3026.         {
  3027.             optionVar -intValue hyperShadeShaderLibraryTabCreated 1;
  3028.             createDiskTab(
  3029.                 $panel,
  3030.                 "secondPaneTabs",
  3031.                 "Shader Library",
  3032.                 $shaderLibraryDir);
  3033.         }
  3034.     }
  3035.  
  3036.     // Update the tab layout option vars now that the tabs have been
  3037.     // initialized
  3038.     //
  3039.     updateTabLayoutOptionVar($panel, "firstPaneTabs");
  3040.  
  3041.     // Now that we have created all the tabs we need, we delete any option vars
  3042.     // which describe tabs that did not get used.
  3043.     //
  3044.     deleteUnusedTabOptionVars($panel);
  3045.  
  3046.     // Update the toolbar and menus to reflect the currently active tab.
  3047.     //
  3048.     refreshToolbar($panel);
  3049.     refreshGraphMenu($panel);
  3050. }
  3051.  
  3052. global proc hyperShadePanelRootDirectoryBrowse()
  3053. {
  3054.     //
  3055.     // Description:
  3056.     //    This procedure is called when the user clicks on the browse button
  3057.     //    beside the root directory text field in the create new tab dialog for
  3058.     //    disk tabs.
  3059.     //    This procedure opens a file browser so the user can browse for the
  3060.     //    directory they want the tab to point at.
  3061.     //
  3062.  
  3063.     setParent hyperShadePanelCreateNewTabWindow;
  3064.  
  3065.     string $initialDirectory = `textField -query -fileName rootDirectoryField`;
  3066.  
  3067.     if (`filetest -d $initialDirectory`)
  3068.     {
  3069.         workspace -dir $initialDirectory;
  3070.     }
  3071.     else
  3072.     {
  3073.         string  $workspace = `workspace -query -fullName`;
  3074.         setWorkingDirectory($workspace, "", "");
  3075.     }
  3076.  
  3077.     fileBrowser("hyperShadePanelRefreshRootDirectoryBrowseField", "Open", "", 4);
  3078. }
  3079.  
  3080. global proc int hyperShadePanelRefreshRootDirectoryBrowseField(
  3081.     string $directory, 
  3082.     string $type)
  3083. {
  3084.     //
  3085.     // Description:
  3086.     //    This procedure is called by the file browser the user uses to choose a
  3087.     //    directory to which a new disk tab will point. 
  3088.     //    This procedure confirms that the user's selection is indeed a
  3089.     //    directory. If so, this procedure updates the root directory text field
  3090.     //    of the create new tab window.
  3091.     //
  3092.     // Returns: 
  3093.     //    1 if the $directory was a valid directory name, thereby causing the
  3094.     //    file browser to close.
  3095.     //    0 if the $directory was not a directory name, thereby causing the file
  3096.     //    browser to remain open.
  3097.     //
  3098.  
  3099.     if (`window -exists hyperShadePanelCreateNewTabWindow`)
  3100.     {
  3101.         if (`filetest -d $directory`)
  3102.         {
  3103.             setParent hyperShadePanelCreateNewTabWindow;
  3104.             textField
  3105.                 -edit
  3106.                 -fileName $directory
  3107.                 rootDirectoryField;
  3108.             return 1;
  3109.         }
  3110.         else
  3111.         {
  3112.             confirmDialog
  3113.                 -title "Invalid directory"
  3114.                 -message 
  3115.                     ("The specified root directory is invalid.\n"
  3116.                         + "Please specify a valid directory.")
  3117.                 -messageAlign center
  3118.                 -button "Close";
  3119.             return 0;
  3120.         }
  3121.     }
  3122.     else
  3123.     {
  3124.         return 1;
  3125.     }
  3126. }
  3127.  
  3128. global proc hyperShadePanelCreateNewTabFinish(
  3129.     string $panel,
  3130.     int $dismiss)
  3131. {
  3132.     //
  3133.     // Description:
  3134.     //    This procedure is called when the user clicks on the Create button in
  3135.     //    the create new tab dialog. 
  3136.     //    This procedure examines the settings of the controls in the create new
  3137.     //    tab dialog to determine the details of the tab the user wants to
  3138.     //    create, and then creates the tab.
  3139.     //
  3140.  
  3141.     setParent hyperShadePanelCreateNewTabWindow;
  3142.     string     $tabLabel;
  3143.     int     $initialPlacementIndex;
  3144.     int     $tabTypeIndex;
  3145.     string     $tabLayout;
  3146.  
  3147.     $tabLabel = `textFieldGrp -query -text newTabNameGrp`;
  3148.     $initialPlacementIndex = `radioButtonGrp -q -select initialPlacementGrp`;
  3149.     $tabTypeIndex = `radioButtonGrp -query -select tabTypeGrp`;
  3150.  
  3151.     if ($initialPlacementIndex == 1)
  3152.     {
  3153.         $tabLayout = "firstPaneTabs";
  3154.     }
  3155.     else
  3156.     {
  3157.         $tabLayout = "secondPaneTabs";
  3158.     }
  3159.  
  3160.     string $newTab = "";
  3161.  
  3162.     switch ($tabTypeIndex)
  3163.     {
  3164.         case 1: // Scene
  3165.             string $filter;
  3166.             $filter = `optionMenuGrp -query -value sceneTabFilterGrp`;
  3167.  
  3168.             if ($filter == "Shading Groups")
  3169.             {
  3170.                 $filter = "ShadingGroups";
  3171.             }
  3172.             else if ($filter == "Post Process")
  3173.             {
  3174.                 $filter = "PostProcess";
  3175.             }
  3176.             else if ($filter == "Materials and Shader Glow")
  3177.             {
  3178.                 $filter = "MaterialsAndShaderGlow";
  3179.             }
  3180.             else if ($filter == "Lights and Optical FX")
  3181.             {
  3182.                 $filter = "LightsAndOpticalFX";
  3183.             }
  3184.             else if ($filter == "Bake Sets")
  3185.             {
  3186.                 $filter = "BakeSets";
  3187.             }
  3188.  
  3189.             $newTab = createSceneTab(
  3190.                 $panel,
  3191.                 $tabLayout,
  3192.                 $tabLabel,
  3193.                 $filter);
  3194.  
  3195.             break;
  3196.         case 2: // Disk
  3197.             string $rootDirectory = 
  3198.                 `textField -query -text rootDirectoryField`;
  3199.             if (!`filetest -d $rootDirectory`)
  3200.             {
  3201.                 confirmDialog
  3202.                     -title "Invalid directory"
  3203.                     -message 
  3204.                         ("The specified root directory is invalid.\n"
  3205.                             + "Please specify a valid directory.")
  3206.                     -messageAlign center
  3207.                     -parent hyperShadePanelCreateNewTabWindow
  3208.                     -button "Close";
  3209.                 return;
  3210.             }
  3211.             int $showFilesOnly = 
  3212.                 `checkBoxGrp -query -value1 onlyShowFilesCheckBox`;
  3213.             
  3214.             if (`about -nt`)
  3215.             {
  3216.                 // The root directory must end in a "\" on NT otherwise weird 
  3217.                 // things happen.
  3218.                 //
  3219.                 $rootDirectory = ($rootDirectory + "\\");
  3220.             }
  3221.  
  3222.             $newTab = createDiskTab(
  3223.                 $panel,
  3224.                 $tabLayout,
  3225.                 $tabLabel,
  3226.                 $rootDirectory);
  3227.  
  3228.             // Specify whether the new tab should show directories
  3229.             //
  3230.             if ($showFilesOnly)
  3231.             {
  3232.                 string $libraryUI = lookupComponentName($newTab);
  3233.                 libraryUIShowFilesOnly($libraryUI);
  3234.             }
  3235.             break;
  3236.         case 3: // Graph
  3237.             $newTab = createGraphTab(
  3238.                 $panel,
  3239.                 $tabLayout,
  3240.                 $tabLabel,
  3241.                 false);
  3242.             break;
  3243.         default:
  3244.             break;
  3245.     }
  3246.  
  3247.     // Update the tab layout option vars now that a tab has been added
  3248.     //
  3249.     updateTabLayoutOptionVar($panel, $tabLayout);
  3250.  
  3251.     if ($newTab != "")
  3252.     {
  3253.         // Bring the new tab to the front
  3254.         //
  3255.         selectTab($panel, $newTab);
  3256.     }
  3257.  
  3258.     if ($dismiss)
  3259.     {
  3260.         // Close the create new tab dialog
  3261.         //
  3262.         deleteUI hyperShadePanelCreateNewTabWindow;
  3263.     }
  3264. }
  3265.  
  3266. global proc hyperShadePanelRefreshCreateNewTabWindow()
  3267. {
  3268.     //
  3269.     // Description:
  3270.     //    This procedure is called when the user changes the type of tab to be
  3271.     //    created in the create new tab dialog. 
  3272.     //    This procedure updates the UI of the create new tab dialog to show only
  3273.     //    the options which are applicable to a tab of the user's chosen type.
  3274.     //
  3275.  
  3276.     setParent hyperShadePanelCreateNewTabWindow;
  3277.  
  3278.     int $tabTypeIndex = `radioButtonGrp -query -select tabTypeGrp`;
  3279.  
  3280.     switch ($tabTypeIndex)
  3281.     {
  3282.         case 1: // Scene
  3283.             optionMenuGrp
  3284.                 -edit
  3285.                 -manage true
  3286.                 sceneTabFilterGrp;
  3287.             rowLayout
  3288.                 -edit
  3289.                 -manage false
  3290.                 directoryNameLayout;
  3291.             checkBoxGrp
  3292.                 -edit
  3293.                 -manage false
  3294.                 onlyShowFilesCheckBox;
  3295.             break;
  3296.         case 2: // Disk
  3297.             optionMenuGrp
  3298.                 -edit
  3299.                 -manage false
  3300.                 sceneTabFilterGrp;
  3301.             rowLayout
  3302.                 -edit
  3303.                 -manage true
  3304.                 directoryNameLayout;
  3305.             checkBoxGrp
  3306.                 -edit
  3307.                 -manage true
  3308.                 onlyShowFilesCheckBox;
  3309.             break;
  3310.         case 3: // Graph
  3311.             optionMenuGrp
  3312.                 -edit
  3313.                 -manage false
  3314.                 sceneTabFilterGrp;
  3315.             rowLayout
  3316.                 -edit
  3317.                 -manage false
  3318.                 directoryNameLayout;
  3319.             checkBoxGrp
  3320.                 -edit
  3321.                 -manage false
  3322.                 onlyShowFilesCheckBox;
  3323.             break;
  3324.         default:
  3325.             break;
  3326.     }
  3327. }
  3328.  
  3329. proc createNewTab(
  3330.     string $panel)
  3331. {
  3332.     //
  3333.     // Description:
  3334.     //    This procedure is called when the user chooses Create New Tab... from
  3335.     //    the hypershade panel menu.
  3336.     //    This procedure builds and opens the create new tab dialog.
  3337.     //
  3338.  
  3339.     if (`window -exists hyperShadePanelCreateNewTabWindow`)
  3340.     {
  3341.         showWindow hyperShadePanelCreateNewTabWindow;
  3342.         return;
  3343.     }
  3344.  
  3345.     //
  3346.     // If we get to here, the create new tab window does not already exist, so 
  3347.     // we will create it.
  3348.     //
  3349.     int $windowWidth = 450;
  3350.     int $windowHeight = 200;
  3351.     
  3352.     window 
  3353.         -title "Create New Tab"
  3354.         -width $windowWidth
  3355.         -height $windowHeight
  3356.         -iconName "New Tab"
  3357.         hyperShadePanelCreateNewTabWindow;
  3358.     
  3359.     setUITemplate -pushTemplate DefaultTemplate;
  3360.     
  3361.     formLayout mainForm;
  3362.         scrollLayout
  3363.             -horizontalScrollBarThickness 0
  3364.             mainScroll;
  3365.  
  3366.             columnLayout scrollColumn;
  3367.                 textFieldGrp
  3368.                     -label "New Tab Name"
  3369.                     newTabNameGrp;
  3370.                 radioButtonGrp
  3371.                     -label "Initial Placement"
  3372.                     -numberOfRadioButtons 2
  3373.                     -label1 "Top"
  3374.                     -label2 "Bottom"
  3375.                     -select 1 // Top is the default
  3376.                     initialPlacementGrp;
  3377.                 radioButtonGrp
  3378.                     -label "Tab Type"
  3379.                     -numberOfRadioButtons 3
  3380.                     -label1 "Scene"
  3381.                     -label2 "Disk"
  3382.                     -label3 "Work Area"
  3383.                     -changeCommand "hyperShadePanelRefreshCreateNewTabWindow"
  3384.                     -select 1 // Scene is the default
  3385.                     tabTypeGrp;
  3386.                 separator -style "in";
  3387.                 formLayout sceneTabOptionsWrap;
  3388.                     optionMenuGrp
  3389.                         -label "Show Nodes Which Are"
  3390.                         sceneTabFilterGrp;
  3391.  
  3392.                         menuItem
  3393.                             -label "Materials"
  3394.                             materialsFilterItem;
  3395.                         menuItem
  3396.                             -label "Materials and Shader Glow"
  3397.                             materialsAndShaderGlowFilterItem;
  3398.                         menuItem
  3399.                             -label "Textures"
  3400.                             texturesFilterItem;
  3401.                         menuItem
  3402.                             -label "Lights"
  3403.                             lightsFilterItem;
  3404.                         menuItem
  3405.                             -label "Lights and Optical FX"
  3406.                             lightsAndOpticalFXFilterItem;
  3407.                         menuItem
  3408.                             -label "Cameras"
  3409.                             camerasFilterItem;
  3410.                         menuItem
  3411.                             -label "Utilities"
  3412.                             utilitiesFilterItem;
  3413.                         menuItem
  3414.                             -label "Shading Groups"
  3415.                             shadingGroupsFilterItem;
  3416.                         menuItem
  3417.                             -label "Post Process"
  3418.                             postProcessFilterItem;
  3419.                         menuItem
  3420.                             -label "Bake Sets"
  3421.                             bakeSetsFilterItem;
  3422.                     setParent -menu ..; // from option menu
  3423.                     formLayout
  3424.                         -edit
  3425.                         -af sceneTabFilterGrp left 0
  3426.                         -af sceneTabFilterGrp right 0
  3427.                         -af sceneTabFilterGrp top 0
  3428.                         -af sceneTabFilterGrp bottom 0
  3429.                         sceneTabOptionsWrap;
  3430.                 setParent ..; // from sceneTabOptionsWrap
  3431.                 formLayout diskTabOptionsWrap;
  3432.                     rowLayout
  3433.                         -numberOfColumns 3
  3434.                         -columnWidth 2 225
  3435.                         -columnWidth 3 25
  3436.                         directoryNameLayout;
  3437.                         text 
  3438.                             -label "Root Directory";
  3439.                         textField
  3440.                             -width 150
  3441.                             rootDirectoryField;
  3442.                         symbolButton
  3443.                             -width 10
  3444.                             -image "navButtonBrowse.xpm" 
  3445.                             -command "hyperShadePanelRootDirectoryBrowse"
  3446.                             browseButton;
  3447.                     setParent ..; // from directoryNameLayout
  3448.                     checkBoxGrp
  3449.                         -numberOfCheckBoxes 1
  3450.                         -label1 "Only Show Files (Hide Directory Tree)"
  3451.                         onlyShowFilesCheckBox;
  3452.                     formLayout
  3453.                         -edit
  3454.                         -af directoryNameLayout left 0
  3455.                         -af directoryNameLayout right 0
  3456.                         -af directoryNameLayout top 0
  3457.                         -an directoryNameLayout bottom
  3458.                         -af onlyShowFilesCheckBox left 0
  3459.                         -af onlyShowFilesCheckBox right 0
  3460.                         -ac onlyShowFilesCheckBox top 0 directoryNameLayout
  3461.                         -af onlyShowFilesCheckBox bottom 0
  3462.                         diskTabOptionsWrap;
  3463.                 setParent ..; // from diskTabOptionsWrap
  3464.             setParent ..; // from scrollColumn
  3465.         setParent ..; // from mainScroll
  3466.  
  3467.         formLayout 
  3468.             -numberOfDivisions 3
  3469.             buttonForm;
  3470.  
  3471.             button
  3472.                 -label "Create"
  3473.                 -command 
  3474.                     ("hyperShadePanelCreateNewTabFinish " 
  3475.                         + $panel
  3476.                         + " "
  3477.                         + "1")
  3478.                 createButton;
  3479.             button
  3480.                 -label "Apply"
  3481.                 -command
  3482.                     ("hyperShadePanelCreateNewTabFinish " 
  3483.                         + $panel
  3484.                         + " "
  3485.                         + "0")
  3486.                 applyButton;
  3487.             button
  3488.                 -label "Close"
  3489.                 -command "deleteUI hyperShadePanelCreateNewTabWindow"
  3490.                 closeButton;
  3491.  
  3492.             formLayout
  3493.                 -edit
  3494.                 -af createButton left 0
  3495.                 -ap createButton right 2 1
  3496.                 -af createButton top 0
  3497.                 -af createButton bottom 0
  3498.  
  3499.                 -ap applyButton left 3 1
  3500.                 -ap applyButton right 2 2
  3501.                 -af applyButton top 0
  3502.                 -af applyButton bottom 0
  3503.  
  3504.                 -ap closeButton left 3 2
  3505.                 -af closeButton right 0
  3506.                 -af closeButton top 0
  3507.                 -af closeButton bottom 0
  3508.                 buttonForm;
  3509.         setParent ..; // from buttonForm
  3510.  
  3511.         formLayout
  3512.             -edit
  3513.  
  3514.             -af mainScroll left 0
  3515.             -af mainScroll right 0
  3516.             -af mainScroll top 0
  3517.             -ac mainScroll bottom 5 buttonForm
  3518.  
  3519.             -af buttonForm left 5
  3520.             -af buttonForm right 5
  3521.             -an buttonForm top
  3522.             -af buttonForm bottom 5
  3523.             
  3524.             mainForm;
  3525.     setParent ..; // from mainForm
  3526.  
  3527.     setUITemplate -popTemplate;
  3528.  
  3529.     hyperShadePanelRefreshCreateNewTabWindow;
  3530.  
  3531.     showWindow hyperShadePanelCreateNewTabWindow;
  3532. }
  3533.  
  3534. global proc hyperShadePanelRenameTabFinish(
  3535.     string $panel)
  3536. {
  3537.     //
  3538.     // Description:
  3539.     //    This procedure is called when the user clicks on the Rename button in
  3540.     //    the rename tab dialog. 
  3541.     //    This procedure examines the settings of the controls in the rename
  3542.     //    tab dialog to determine the new name for the tab, then renames the tab.
  3543.     //
  3544.  
  3545.     setParent hyperShadePanelRenameTabWindow;
  3546.     string     $tabLabel;
  3547.  
  3548.     $tabLabel = `textFieldGrp -query -text newTabNameGrp`;
  3549.  
  3550.     setTabLabel(activeTab($panel), $tabLabel);
  3551.     deleteUI hyperShadePanelRenameTabWindow;
  3552. }
  3553.  
  3554. proc renameTab(
  3555.     string $panel)
  3556. {
  3557.     //
  3558.     // Description:
  3559.     //    This procedure is called when the user chooses Rename Tab... from
  3560.     //    the hypershade panel menu.
  3561.     //    This procedure builds and opens the rename tab dialog.
  3562.     //
  3563.  
  3564.     if (`window -exists hyperShadePanelRenameTabWindow`)
  3565.     {
  3566.         showWindow hyperShadePanelRenameTabWindow;
  3567.         return;
  3568.     }
  3569.  
  3570.     //
  3571.     // If we get to here, the rename tab window does not already exist, so 
  3572.     // we will create it.
  3573.     //
  3574.     
  3575.     int $windowWidth = 425;
  3576.     int $windowHeight = 110;
  3577.  
  3578.     window 
  3579.         -title "Rename Tab"
  3580.         -width $windowWidth
  3581.         -height $windowHeight
  3582.         -iconName "Rename Tab"
  3583.         hyperShadePanelRenameTabWindow;
  3584.     
  3585.     setUITemplate -pushTemplate DefaultTemplate;
  3586.     
  3587.     formLayout mainForm;
  3588.         columnLayout mainColumn;
  3589.             textFieldGrp 
  3590.                 -label "Old Tab Name"
  3591.                 -editable false
  3592.                 -text `activeTabLabel($panel)`
  3593.                 oldTabNameGrp;
  3594.             textFieldGrp 
  3595.                 -label "New Tab Name"
  3596.                 newTabNameGrp;
  3597.         setParent ..; // from mainColumn
  3598.  
  3599.         formLayout 
  3600.             -numberOfDivisions 2
  3601.             buttonForm;
  3602.  
  3603.             button
  3604.                 -label "Rename"
  3605.                 -command ("hyperShadePanelRenameTabFinish " + $panel)
  3606.                 renameButton;
  3607.             button
  3608.                 -label "Close"
  3609.                 -command "deleteUI hyperShadePanelRenameTabWindow"
  3610.                 closeButton;
  3611.  
  3612.             formLayout
  3613.                 -edit
  3614.                 -af renameButton left 5
  3615.                 -ap renameButton right 2 1
  3616.                 -af renameButton top 5
  3617.                 -af renameButton bottom 5
  3618.  
  3619.                 -ap closeButton left 3 1
  3620.                 -af closeButton right 5
  3621.                 -af closeButton top 5
  3622.                 -af closeButton bottom 5
  3623.                 buttonForm;
  3624.         setParent ..; // from buttonForm
  3625.  
  3626.         formLayout
  3627.             -edit
  3628.  
  3629.             -af mainColumn left 0
  3630.             -af mainColumn right 0
  3631.             -af mainColumn top 0
  3632.             -af mainColumn bottom 35
  3633.  
  3634.             -af buttonForm left 0
  3635.             -af buttonForm right 0
  3636.             -ac buttonForm top 0 mainColumn
  3637.             -af buttonForm bottom 0
  3638.             
  3639.             mainForm;
  3640.     setParent ..; // from mainForm
  3641.  
  3642.     setUITemplate -popTemplate;
  3643.  
  3644.     showWindow hyperShadePanelRenameTabWindow;
  3645. }
  3646.  
  3647. global proc string hyperShadePanelCreate(
  3648.     string $as,
  3649.     string $type)
  3650. {
  3651.     //
  3652.     // Description:
  3653.     //    This procedure is called when the user chooses to create a node from
  3654.     //    the hyperShadePanel Create menu.
  3655.     //    This procedure creates a node of the nodeType specified in $type, and
  3656.     //    using the $as argument to hook up the new node so that it may be
  3657.     //    properly filtered within the UI.
  3658.     //    Mostly this procedure calls renderCreateNode to perform the creation.
  3659.     //
  3660.     // Returns: 
  3661.     //    The name of the node which was created.
  3662.     //
  3663.  
  3664.     string $name;
  3665.  
  3666.     if ($as == "shader")
  3667.     {
  3668.         int $withShadingGroup = 
  3669.             `optionVar -query createMaterialsWithShadingGroup`;
  3670.  
  3671.         string $classification[] = `getClassification $type`;
  3672.         string $dest;
  3673.  
  3674.         if (substring($classification[0], 1, 19) == "shader/displacement") 
  3675.         {
  3676.             $dest = "displacementShader";
  3677.         } 
  3678.         else if (substring($classification[0], 1, 13) == "shader/volume") 
  3679.         {
  3680.             $dest = "volumeShader";
  3681.         } 
  3682.         else 
  3683.         {
  3684.             $dest = "surfaceShader";
  3685.         }
  3686.         
  3687.         string $name = 
  3688.             renderCreateNode( 
  3689.                 "-asShader", 
  3690.                 $dest, 
  3691.                 $type, 
  3692.                 "", 
  3693.                 0, 
  3694.                 0, 
  3695.                 1,
  3696.                 $withShadingGroup,
  3697.                 0, 
  3698.                 "");
  3699.     }
  3700.     else if ($as == "2dTexture")
  3701.     {
  3702.         int $asNormal;
  3703.         int $asProjection;
  3704.         int $asStencil;
  3705.         int $withPlacement;
  3706.  
  3707.         $asNormal = 
  3708.             (`optionVar -query create2dTextureType` == "normal");
  3709.         $asProjection = 
  3710.             (`optionVar -query create2dTextureType` == "projection");
  3711.         $asStencil = 
  3712.             (`optionVar -query create2dTextureType` == "stencil");
  3713.         $withPlacement = 
  3714.             (`optionVar -query createTexturesWithPlacement`);
  3715.  
  3716.         $name = 
  3717.             renderCreateNode(
  3718.                 "-as2DTexture",
  3719.                 "",
  3720.                 $type,
  3721.                 "", 
  3722.                 $asProjection, 
  3723.                 $asStencil,
  3724.                 $withPlacement,
  3725.                 0, 
  3726.                 0, 
  3727.                 "");
  3728.     }
  3729.     else if ($as == "3dTexture")
  3730.     {
  3731.         int $withPlacement;
  3732.         $withPlacement = (`optionVar -query createTexturesWithPlacement`);
  3733.         $name = 
  3734.             renderCreateNode(
  3735.                 "-as3DTexture", 
  3736.                 "",
  3737.                 $type,
  3738.                 "",
  3739.                 0, 
  3740.                 0,
  3741.                 $withPlacement,
  3742.                 0,
  3743.                 0,
  3744.                 "");
  3745.     }
  3746.     else if ($as == "otherTexture")
  3747.     {
  3748.         $name = `renderCreateNode "-asTexture" "" $type "" 0 0 0 0 0 ""`;
  3749.     }
  3750.     else if ($as == "light")
  3751.     {
  3752.         $name = `renderCreateNode "-asLight" "" $type "" 0 0 0 0 0 ""`;
  3753.     }
  3754.     else if ($as == "utility")
  3755.     {
  3756.         $name = `renderCreateNode "-asUtility" "" $type "" 0 0 0 0 0 ""`;
  3757.     }
  3758.     else if ($as == "camera")
  3759.     {
  3760.         string $cameraNames[];
  3761.         $cameraNames = `camera`;
  3762.         $name = $cameraNames[0];
  3763.     }
  3764.     else if ($as == "node")
  3765.     {
  3766.         $name = `createNode $type`;
  3767.     }
  3768.  
  3769.     return $name;
  3770. }
  3771.  
  3772. global proc buildCreateSubMenu(
  3773.     string $classification, 
  3774.     string $callback)
  3775. {
  3776.     //
  3777.     // Description:
  3778.     //    This procedure is called from buildMainMenu().
  3779.     //    This procedure builds a menu which allows the user to create nodes of
  3780.     //    the specified classification.
  3781.     //    The specified callback script is the one which is called to do the
  3782.     //    creation of a node of a particular type.
  3783.     //
  3784.  
  3785.     string $types[] = `listNodeTypes $classification`;
  3786.  
  3787.     for($type in $types) 
  3788.     {
  3789.         string $typeString = `interToUI $type`;
  3790.         menuItem 
  3791.             -label $typeString
  3792.             -annotation 
  3793.                 ("Create a new " 
  3794.                     + $typeString 
  3795.                     + " node")
  3796.             -command ($callback + " " + $type ); 
  3797.     }
  3798. }
  3799.  
  3800. proc buildCreateNodesSubMenu(
  3801.     string $types[], 
  3802.     string $callback)
  3803. {
  3804.     //
  3805.     // Description:
  3806.     //    This procedure is called from buildMainMenu().
  3807.     //    This procedure builds menu items to create nodes of the nodeTypes
  3808.     //    specified in $types[].
  3809.     //    The specified callback script is the one which is called to do the
  3810.     //    creation of a node of a particular type.
  3811.     //
  3812.  
  3813.     for($type in $types) 
  3814.     {
  3815.         string $typeString = `interToUI $type`;
  3816.         menuItem 
  3817.             -label $typeString
  3818.             -annotation 
  3819.                 ("Create a new " 
  3820.                     + $typeString 
  3821.                     + " node")
  3822.             -command ($callback + "(\"" + $type + "\")");
  3823.     }
  3824. }
  3825.  
  3826. proc buildMainMenu(
  3827.     string $panel,
  3828.     int $isPopupMenu)
  3829. //
  3830. // Description:
  3831. //    This procedure is called when the hypershade panel is first opened.
  3832. //    This procedure creates menus in the top menubar of the hypershade panel. 
  3833. //
  3834. {
  3835.     string $menuPrefix;
  3836.  
  3837.     if ($isPopupMenu)
  3838.     {
  3839.         $menuPrefix = "hyperShadePopupMenu";
  3840.     }
  3841.     else
  3842.     {
  3843.         $menuPrefix = "hyperShadePanelMenu";
  3844.     }
  3845.  
  3846.     // Build the File menu
  3847.     //
  3848.     if ($isPopupMenu)
  3849.     {
  3850.         menuItem
  3851.             -subMenu true
  3852.             -label "File" 
  3853.             -tearOff true 
  3854.             ($menuPrefix + "FileMenu");
  3855.     }
  3856.     else
  3857.     {
  3858.         menu 
  3859.             -label "File" 
  3860.             -tearOff true 
  3861.             ($menuPrefix + "FileMenu");
  3862.     }
  3863.  
  3864.         menuItem 
  3865.             -label "Import..." 
  3866.             -annotation "Import a shading network or other file"
  3867.             -command 
  3868.                 ("hyperShadePanelMenuCommand(\"" 
  3869.                     + $panel 
  3870.                     + "\", \"import\")");
  3871.         menuItem -divider true;
  3872.         menuItem 
  3873.             -label "Import Selected Scene Files" 
  3874.             -annotation 
  3875.                 ("Import the selected Maya files, such as shading networks")
  3876.             -command 
  3877.                 ("hyperShadePanelMenuCommand(\"" 
  3878.                     + $panel 
  3879.                     + "\", \"importSelectedSceneFiles\")");
  3880.         menuItem -label "Import Selected Image Files" -subMenu true;
  3881.             menuItem
  3882.                 -label "As Normal"
  3883.                 -annotation 
  3884.                     ("As Normal: Import the selected image files as normal "
  3885.                         + "file textures")
  3886.                 -command 
  3887.                     ("hyperShadePanelMenuCommand(\"" 
  3888.                         + $panel 
  3889.                         + "\", \"importSelectedImageFilesAsNormal\")");
  3890.             menuItem
  3891.                 -label "As Projection"
  3892.                 -annotation 
  3893.                     ("As Projection: Import the selected image files as "
  3894.                         + "projected file textures")
  3895.                 -command 
  3896.                     ("hyperShadePanelMenuCommand(\"" 
  3897.                         + $panel 
  3898.                         + "\", \"importSelectedImageFilesAsProjection\")");
  3899.             menuItem
  3900.                 -label "As Stencil"
  3901.                 -annotation 
  3902.                     ("As Stencil: Import the selected image files as "
  3903.                         + "stencilled file textures")
  3904.                 -command 
  3905.                     ("hyperShadePanelMenuCommand(\"" 
  3906.                         + $panel 
  3907.                         + "\", \"importSelectedImageFilesAsStencil\")");
  3908.             menuItem -divider true;
  3909.             $importIncludePlacementItem = 
  3910.                 `menuItem 
  3911.                     -label "Include Placement"
  3912.                     -checkBox true
  3913.                     -annotation 
  3914.                         ("Include Placement: If on, new textures are created "
  3915.                             + "with an associated placement node")
  3916.                     importIncludePlacementItem`;
  3917.             menuItem
  3918.                 -edit
  3919.                 -checkBox 
  3920.                     `optionVar -query createTexturesWithPlacement` 
  3921.                 -command 
  3922.                     ("optionVar -intValue createTexturesWithPlacement "
  3923.                         + "`menuItem -query -checkBox " 
  3924.                         + $importIncludePlacementItem
  3925.                         + "`; refreshCreateNodeUI();")
  3926.                 $importIncludePlacementItem;
  3927.             setParent -menu ..;
  3928.         menuItem -divider true;
  3929.         menuItem 
  3930.             -label "Export Selected Network"
  3931.             -annotation "Export the selected shading network or other items"
  3932.             -command 
  3933.                 ("hyperShadePanelMenuCommand(\"" 
  3934.                     + $panel 
  3935.                     + "\", \"exportSelectedNetwork\")");
  3936.     
  3937.     // Build the Edit menu
  3938.     //
  3939.     if ($isPopupMenu)
  3940.     {
  3941.         setParent -menu ..;
  3942.         menuItem
  3943.             -postMenuCommand 
  3944.                 ("hyperShadePanelBuildEditMenu " 
  3945.                     + $panel 
  3946.                     + " " 
  3947.                     + $menuPrefix 
  3948.                     + "EditMenu")
  3949.             -subMenu true
  3950.             -label "Edit" 
  3951.             -allowOptionBoxes true 
  3952.             -tearOff true 
  3953.             ($menuPrefix + "EditMenu");
  3954.     }
  3955.     else
  3956.     {
  3957.         menu
  3958.             -postMenuCommand 
  3959.                 ("hyperShadePanelBuildEditMenu " 
  3960.                     + $panel 
  3961.                     + " " 
  3962.                     + $menuPrefix 
  3963.                     + "EditMenu")
  3964.             -label "Edit" 
  3965.             -allowOptionBoxes true 
  3966.             -tearOff true 
  3967.             ($menuPrefix + "EditMenu");
  3968.     }
  3969.  
  3970.     // Build the View menu
  3971.     //
  3972.     if ($isPopupMenu)
  3973.     {
  3974.         setParent -menu ..;
  3975.         menuItem
  3976.             -subMenu true
  3977.             -label "View" 
  3978.             -tearOff true 
  3979.             ($menuPrefix + "ViewMenu");
  3980.     }
  3981.     else
  3982.     {
  3983.         menu 
  3984.             -label "View" 
  3985.             -tearOff true 
  3986.             ($menuPrefix + "ViewMenu");
  3987.     }
  3988.  
  3989.         menuItem 
  3990.             -label "Frame All"
  3991.             -annotation "Frame All: Reset the view to frame all nodes/files"
  3992.             -command 
  3993.                 ("hyperShadePanelMenuCommand(\"" 
  3994.                     + $panel 
  3995.                     + "\", \"frameAll\")");
  3996.         menuItem 
  3997.             -label "Frame Selected"
  3998.             -annotation 
  3999.                 "Frame Selection: Reset the view to frame selected nodes/files"
  4000.             -command 
  4001.                 ("hyperShadePanelMenuCommand(\"" 
  4002.                     + $panel 
  4003.                     + "\", \"frameSelected\")");
  4004.         
  4005.     // Build the Create menu
  4006.     //
  4007.     if ($isPopupMenu)
  4008.     {
  4009.         setParent -menu ..;
  4010.         menuItem
  4011.             -subMenu true
  4012.             -label "Create" 
  4013.             -allowOptionBoxes true
  4014.     /*        -postMenuCommand (
  4015.                 "hyperShadePanelBuildCreateMenu " 
  4016.                 + $panel 
  4017.                 + " " 
  4018.                 + $menuPrefix 
  4019.                 + "CreateMenu")
  4020.             -postMenuCommandOnce true*/
  4021.             -tearOff true 
  4022.             ($menuPrefix + "CreateMenu");
  4023.     }
  4024.     else
  4025.     {
  4026.         menu 
  4027.             -label "Create" 
  4028.             -allowOptionBoxes true 
  4029.         /*    -postMenuCommand (
  4030.                 "hyperShadePanelBuildCreateMenu " 
  4031.                 + $panel 
  4032.                 + " " 
  4033.                 + $menuPrefix 
  4034.                 + "CreateMenu")
  4035.             -postMenuCommandOnce false*/
  4036.             -tearOff true 
  4037.             ($menuPrefix + "CreateMenu");
  4038.     }
  4039.  
  4040.     hyperShadePanelBuildCreateMenu($panel, $menuPrefix);
  4041.     // Build the Tabs menu
  4042.     //
  4043.     if ($isPopupMenu)
  4044.     {
  4045.         setParent -menu ..;
  4046.         menuItem
  4047.             -subMenu true
  4048.             -label "Tabs" 
  4049.             -tearOff true 
  4050.             ($menuPrefix + "TabsMenu");
  4051.     }
  4052.     else
  4053.     {
  4054.         menu 
  4055.             -label "Tabs" 
  4056.             -tearOff true 
  4057.             ($menuPrefix + "TabsMenu");
  4058.     }
  4059.  
  4060.         menuItem 
  4061.             -label "Create New Tab..."
  4062.             -annotation ("Create New Tab: Add a new tab to the Hypershade")
  4063.             -command 
  4064.                 ("hyperShadePanelMenuCommand(\"" 
  4065.                     + $panel 
  4066.                     + "\", \"createNewTab\")");
  4067.         menuItem -divider true;
  4068.         menuItem 
  4069.             -label "Move Tab Up" 
  4070.             -annotation 
  4071.                 ("Move Tab Up: Move the frontmost bottom tab to the top")
  4072.             -command 
  4073.                 ("hyperShadePanelMenuCommand(\"" 
  4074.                     + $panel 
  4075.                     + "\", \"moveTabUp\")")
  4076.             tabsMoveTabUpItem;
  4077.         menuItem 
  4078.             -label "Move Tab Down"
  4079.             -annotation 
  4080.                 ("Move Tab Down: Move the frontmost top tab to the bottom")
  4081.             -command 
  4082.                 ("hyperShadePanelMenuCommand(\"" 
  4083.                     + $panel 
  4084.                     + "\", \"moveTabDown\")")
  4085.             tabsMoveTabDownItem;
  4086.         menuItem 
  4087.             -label "Move Tab Left" 
  4088.             -annotation 
  4089.                 ("Move Tab Left: Move the active tab left within its tab "
  4090.                     + "section")
  4091.             -command 
  4092.                 ("hyperShadePanelMenuCommand(\"" 
  4093.                     + $panel 
  4094.                     + "\", \"moveTabLeft\")");
  4095.         menuItem 
  4096.             -label "Move Tab Right" 
  4097.             -annotation 
  4098.                 ("Move Tab Right: Move the active tab right within its tab "
  4099.                     + "section")
  4100.             -command 
  4101.                 ("hyperShadePanelMenuCommand(\"" 
  4102.                     + $panel 
  4103.                     + "\", \"moveTabRight\")");
  4104.         menuItem -divider true;
  4105.         menuItem 
  4106.             -label "Rename Tab..." 
  4107.             -annotation 
  4108.                 ("Rename Tab: Rename the current tab")
  4109.             -command 
  4110.                 ("hyperShadePanelMenuCommand(\"" 
  4111.                     + $panel 
  4112.                     + "\", \"renameTab\")");
  4113.         menuItem -divider true;
  4114.         menuItem 
  4115.             -label "Remove Tab"
  4116.             -annotation 
  4117.                 ("Remove Tab: Remove the active tab from Hypershade")
  4118.             -command 
  4119.                 ("hyperShadePanelMenuCommand(\"" 
  4120.                     + $panel 
  4121.                     + "\", \"removeTab\")");
  4122.         menuItem 
  4123.             -label "Revert to Default Tabs" 
  4124.             -annotation 
  4125.                 ("Revert to Default Tabs: Remove all tabs from Hypershade and "
  4126.                     + "create default tabs to replace them")
  4127.             -command 
  4128.                 ("hyperShadePanelMenuCommand(\"" 
  4129.                     + $panel 
  4130.                     + "\", \"revertToDefaultTabs\")");
  4131.         menuItem -divider true;
  4132.             
  4133.         radioMenuItemCollection;
  4134.         menuItem 
  4135.             -label "Show Top Tabs Only"
  4136.             -radioButton 
  4137.                 (`optionVar -q hyperShadePanelTabSectionsShown` 
  4138.                     == "showTopTabsOnly")
  4139.             -annotation
  4140.                 ("Show Top Tabs Only: Hide the bottom tab section")
  4141.             -command 
  4142.                 ("hyperShadePanelMenuCommand(\"" 
  4143.                     + $panel 
  4144.                     + "\", \"showTopTabsOnly\")")
  4145.             tabsShowTopTabsOnlyItem;
  4146.         menuItem 
  4147.             -label "Show Bottom Tabs Only"
  4148.             -radioButton 
  4149.                 (`optionVar -q hyperShadePanelTabSectionsShown` 
  4150.                     == "showBottomTabsOnly")
  4151.             -annotation
  4152.                 ("Show Bottom Tabs Only: Hide the top tab section")
  4153.             -command 
  4154.                 ("hyperShadePanelMenuCommand(\"" 
  4155.                     + $panel 
  4156.                     + "\", \"showBottomTabsOnly\")")
  4157.             tabsShowBottomTabsOnlyItem;
  4158.         menuItem 
  4159.             -label "Show Top And Bottom Tabs"
  4160.             -radioButton 
  4161.                 (`optionVar -q hyperShadePanelTabSectionsShown` 
  4162.                     == "showTopAndBottomTabs")
  4163.             -annotation
  4164.                 ("Show Both: Show both tab sections")
  4165.             -command 
  4166.                 ("hyperShadePanelMenuCommand(\"" 
  4167.                     + $panel 
  4168.                     + "\", \"showTopAndBottomTabs\")")
  4169.             tabsShowTopAndBottomTabsItem;
  4170.         menuItem -divider true;
  4171.         string $currentTabMenu = 
  4172.             `menuItem 
  4173.                 -label "Current Tab" 
  4174.                 -subMenu true
  4175.                 currentTabMenu`;
  4176.             setParent -menu ..;
  4177.         menuItem
  4178.             -edit
  4179.             -postMenuCommand 
  4180.                 ("hyperShadePanelBuildTabOptionsMenu " 
  4181.                     + $panel
  4182.                     + " "
  4183.                     + $currentTabMenu)
  4184.             $currentTabMenu;
  4185.  
  4186.     // Build the Graph menu
  4187.     //
  4188.     if ($isPopupMenu)
  4189.     {
  4190.         setParent -menu ..;
  4191.         menuItem
  4192.             -subMenu true
  4193.             -label "Graph" 
  4194.             -tearOff true 
  4195.             ($menuPrefix + "GraphMenu");
  4196.     }
  4197.     else
  4198.     {
  4199.         menu 
  4200.             -label "Graph" 
  4201.             -tearOff true 
  4202.             ($menuPrefix + "GraphMenu");
  4203.     }
  4204.  
  4205.         menuItem 
  4206.             -label "Graph Materials on Selected Objects"
  4207.             -annotation 
  4208.                 ("Graph Materials on Selected Objects: "
  4209.                     + "Graph the shading network currently applied to the "
  4210.                     + "selected objects")
  4211.             -command 
  4212.                 ("hyperShadePanelGraphCommand(\"" 
  4213.                     + $panel 
  4214.                     + "\", \"graphMaterials\")");
  4215.         menuItem -divider true;
  4216.         menuItem 
  4217.             -label "Clear Graph"
  4218.             -annotation "Clear View: Clear the active graph tab"
  4219.             -command 
  4220.                 ("hyperShadePanelGraphCommand(\"" 
  4221.                     + $panel 
  4222.                     + "\", \"clearGraph\")")
  4223.             clearGraphItem;
  4224.         menuItem -divider true;
  4225.         menuItem 
  4226.             -label "Input and Output Connections"
  4227.             -annotation 
  4228.                 ("Show Input and Output Connections: Display entire network for "
  4229.                     + "selected nodes")
  4230.             -command 
  4231.                 ("hyperShadePanelGraphCommand(\"" 
  4232.                     + $panel 
  4233.                     + "\", \"showUpAndDownstream\")");
  4234.         menuItem 
  4235.             -label "Input Connections"
  4236.             -annotation 
  4237.                 ("Show Input Connections: Display network affecting selected "
  4238.                     + "nodes")
  4239.             -command 
  4240.                 ("hyperShadePanelGraphCommand(\"" 
  4241.                     + $panel 
  4242.                     + "\", \"showUpstream\")");
  4243.         menuItem 
  4244.             -label "Output Connections"
  4245.             -annotation 
  4246.                 ("Show Output Connections: Display network affected by selected nodes")
  4247.             -command 
  4248.                 ("hyperShadePanelGraphCommand(\"" 
  4249.                     + $panel 
  4250.                     + "\", \"showDownstream\")");
  4251.         menuItem -divider true;
  4252.         menuItem
  4253.             -label "Show Previous Graph"
  4254.             -annotation
  4255.                 ("Show Previous Graph: Display the shading network graphed"
  4256.                     + " before the current one.")
  4257.             -command 
  4258.                 ("hyperShadePanelGraphCommand(\"" 
  4259.                     + $panel 
  4260.                     + "\", \"showPreviousGraph\")")
  4261.             showPreviousGraphItem;
  4262.         menuItem
  4263.             -label "Show Next Graph"
  4264.             -annotation
  4265.                 ("Show Next Graph: Display the shading network graphed"
  4266.                     + " after the current one.")
  4267.             -command 
  4268.                 ("hyperShadePanelGraphCommand(\"" 
  4269.                     + $panel 
  4270.                     + "\", \"showNextGraph\")")
  4271.             showNextGraphItem;
  4272.         menuItem -divider true;
  4273.         menuItem 
  4274.             -label "Add Selected to Graph"
  4275.             -annotation 
  4276.                 ("Add Selected to Graph: Add the selected nodes to the "
  4277.                     + "active graph tab")
  4278.             -command 
  4279.                 ("hyperShadePanelGraphCommand(\"" 
  4280.                     + $panel 
  4281.                     + "\", \"addSelected\")");
  4282.         menuItem 
  4283.             -label "Remove Selected from Graph"
  4284.             -annotation 
  4285.                 ("Remove Selected from Graph: Remove the selected nodes from "
  4286.                     + "the active graph tab (without deleting them)")
  4287.             -command 
  4288.                 ("hyperShadePanelGraphCommand(\"" 
  4289.                     + $panel 
  4290.                     + "\", \"removeSelected\")");
  4291.         menuItem -divider true;
  4292.         menuItem 
  4293.             -label "Rearrange Graph"
  4294.             -annotation 
  4295.                 ("Rearrange Graph: Automatically re-arrange layout of the "
  4296.                     + "active graph tab")
  4297.             -command 
  4298.                 ("hyperShadePanelGraphCommand(\"" 
  4299.                     + $panel 
  4300.                     + "\", \"rearrangeGraph\")")
  4301.             rearrangeGraphItem;
  4302.  
  4303.         if ($isPopupMenu)
  4304.         {
  4305.             // Enable some graph menu items only if a graph tab (work area) is 
  4306.             // visible
  4307.             //
  4308.             int $enable;
  4309.             $enable = isGraphTabVisible($panel);
  4310.  
  4311.             menuItem 
  4312.                 -edit
  4313.                 -enable $enable
  4314.                 clearGraphItem;
  4315.             menuItem 
  4316.                 -edit
  4317.                 -enable $enable
  4318.                 rearrangeGraphItem;
  4319.             menuItem 
  4320.                 -edit
  4321.                 -enable $enable
  4322.                 showPreviousGraphItem;
  4323.             menuItem 
  4324.                 -edit
  4325.                 -enable $enable
  4326.                 showNextGraphItem;
  4327.         }
  4328.  
  4329.     
  4330.     // Build the Window menu
  4331.     //
  4332.     if ($isPopupMenu)
  4333.     {
  4334.         setParent -menu ..;
  4335.         menuItem
  4336.             -subMenu true
  4337.             -label "Window" 
  4338.             -tearOff true 
  4339.             ($menuPrefix + "WindowMenu");
  4340.     }
  4341.     else
  4342.     {
  4343.         menu 
  4344.             -label "Window" 
  4345.             -tearOff true 
  4346.             ($menuPrefix + "WindowMenu");
  4347.     }
  4348.  
  4349.         menuItem -label "Attribute Editor..."
  4350.             -annotation 
  4351.                 ("Attribute Editor: Edit the attributes of the selected object")
  4352.             -c ("showEditor `select`");
  4353.         menuItem -label "Attribute Spread Sheet"
  4354.             -annotation 
  4355.                 ("Attribute Spread Sheet: "
  4356.                     + "Edit the attributes of the selected object(s)")
  4357.             -c ("SpreadSheetWindow");
  4358.         menuItem -divider true;
  4359.         menuItem 
  4360.             -label "Connection Editor..." 
  4361.             -annotation 
  4362.                 ("Connection Editor: " 
  4363.                     + "Make connections between node attributes")
  4364.             -command ("connectWindow");
  4365.         menuItem 
  4366.             -label "Connect Selected..." 
  4367.             -annotation
  4368.                 ("Connect Selected: Make connections involving "
  4369.                     + "the selected node's attributes")
  4370.             -command 
  4371.                 ("string $sel[] = `ls -sl`; connectWindowWith $sel[0] $sel[1]");
  4372.  
  4373.     // Build the Options menu
  4374.     //
  4375.     if ($isPopupMenu)
  4376.     {
  4377.         setParent -menu ..;
  4378.         menuItem
  4379.             -subMenu true
  4380.             -label "Options" 
  4381.             -tearOff true 
  4382.             ($menuPrefix + "OptionsMenu");
  4383.     }
  4384.     else
  4385.     {
  4386.         menu 
  4387.             -label "Options" 
  4388.             -tearOff true 
  4389.             ($menuPrefix + "OptionsMenu");
  4390.     }
  4391.         string $createBarMenu = 
  4392.             `menuItem 
  4393.                 -label "Create Bar" 
  4394.                 -subMenu true
  4395.                 createBarMenu`;
  4396.             setParent -menu ..;
  4397.         menuItem
  4398.             -edit
  4399.             -postMenuCommand 
  4400.                 ("hyperShadePanelBuildCreateBarOptionsMenu " 
  4401.                     + $panel
  4402.                     + " "
  4403.                     + $createBarMenu)
  4404.             $createBarMenu;
  4405.         menuItem -divider true;
  4406.  
  4407.         int $keepSwatchesAtCurrentResolution = `optionVar -query keepSwatchesAtCurrentResolution`;
  4408.         string $keepSwatchesAtCurrentResolutionItem = 
  4409.             `menuItem 
  4410.                 -label "Keep Swatches at Current Resolution" 
  4411.                 -annotation 
  4412.                     ("Keep Swatches at Current Resolution: Reuse the existing "
  4413.                         + "rendering of swatches to make display updates "
  4414.                         + "quicker")
  4415.                 -checkBox $keepSwatchesAtCurrentResolution
  4416.                 keepSwatchesAtCurrentResolution`;
  4417.         menuItem 
  4418.             -edit
  4419.             -command 
  4420.                 ("optionVar "
  4421.                     + "-intValue keepSwatchesAtCurrentResolution "
  4422.                     + "`menuItem -query -checkBox " 
  4423.                     + $keepSwatchesAtCurrentResolutionItem
  4424.                     + "`; hyperShadePanelMenuCommand(\"" 
  4425.                     + $panel 
  4426.                     + "\", \"keepSwatchesAtCurrentResolution\")")
  4427.             $keepSwatchesAtCurrentResolutionItem; 
  4428.  
  4429.         int $isClearBeforeSet = `optionVar -query hsClearBeforeGraphing`;
  4430.         string $clearBeforeItem = 
  4431.             `menuItem 
  4432.                 -label "Clear Before Graphing" 
  4433.                 -annotation 
  4434.                     ("Clear all nodes from the work area before graphing.")
  4435.                 -checkBox $isClearBeforeSet
  4436.                 clearBeforeItem`;
  4437.         menuItem 
  4438.             -edit
  4439.             -command 
  4440.                 ("optionVar "
  4441.                     + "-intValue hsClearBeforeGraphing "
  4442.                     + "`menuItem -query -checkBox " 
  4443.                     + $clearBeforeItem
  4444.                     + "`")
  4445.             $clearBeforeItem;
  4446.  
  4447.     // Add support for the Context Sensitive Help Menu.
  4448.     //
  4449.     addContextHelpProc $panel "hyperShadePanelBuildContextHelpItems";
  4450.             
  4451.     // Set the menu bar visibility
  4452.     //
  4453.     int $menusOkayInPanels = `optionVar -q allowMenusInPanels`;
  4454.     panel -e -mbv $menusOkayInPanels $panel;
  4455. }
  4456.  
  4457. // ---------------------------------------------------------------------------
  4458. //     Global procedures
  4459. // 
  4460.  
  4461. global proc hyperShadePanelBuildContextHelpItems(
  4462.     string $nameRoot, 
  4463.     string $menuParent)
  4464. {
  4465.     //
  4466.     // Description:
  4467.     //    This procedure is called as the Help menu for this panel is being
  4468.     //    built.
  4469.     //    This procedure builds the menu item which provides help on the
  4470.     //    Hypershade.
  4471.     //    $nameRoot is the name to use as the root of all item names
  4472.     //    $menuParent is the name of the parent of this menu
  4473.     //
  4474.  
  4475.     menuItem -label "Help on Hypershade..."
  4476.         -enableCommandRepeat false
  4477.         -command "showHelp Hypershade";
  4478.     menuItem -label "Help on Shader Library..."
  4479.         -enableCommandRepeat false
  4480.         -command "showHelp ShaderLibrary";
  4481. }
  4482.  
  4483. global proc hyperShadePanelBuildEditMenu(
  4484.     string $panel, 
  4485.     string $parent)
  4486. {
  4487.     //
  4488.     // Description:
  4489.     //    This procedure is called every time the Edit menu is opened.
  4490.     //    This procedure builds the Edit menu. 
  4491.     //
  4492.  
  4493.     menu -edit -deleteAllItems $parent;
  4494.  
  4495.     setParent -menu $parent;
  4496.  
  4497.     menuItem 
  4498.         -label "Delete"
  4499.         -annotation "Delete: Delete the selected node(s)"
  4500.         -command 
  4501.             ("hyperShadePanelMenuCommand(\"" 
  4502.                 + $panel 
  4503.                 + "\", \"delete\")");
  4504.  
  4505.     menuItem 
  4506.         -label "Delete Unused Nodes"
  4507.         -annotation 
  4508.             ("Delete Unused Nodes: Delete all shading nodes not "
  4509.                 + "assigned to surfaces")
  4510.         -command 
  4511.             ("hyperShadePanelMenuCommand(\"" 
  4512.                 + $panel 
  4513.                 + "\", \"deleteUnusedNodes\")");
  4514.  
  4515.     menuItem -label "Delete All by Type" -subMenu true;
  4516.  
  4517.         menuItem 
  4518.             -label "Shading Groups and Materials"
  4519.             -annotation "Delete all Shading Groups and Materials"
  4520.             -command 
  4521.                 ("hyperShadePanelMenuCommand(\"" 
  4522.                     + $panel 
  4523.                     + "\", \"deleteShadingGroupsAndMaterials\")");
  4524.  
  4525.         menuItem 
  4526.             -label "Textures"
  4527.             -annotation "Delete all Textures"
  4528.             -command 
  4529.                 ("hyperShadePanelMenuCommand(\"" 
  4530.                     + $panel 
  4531.                     + "\", \"deleteTextures\")");
  4532.  
  4533.         menuItem 
  4534.             -label "Lights"
  4535.             -annotation "Delete all Lights"
  4536.             -command 
  4537.                 ("hyperShadePanelMenuCommand(\"" 
  4538.                     + $panel 
  4539.                     + "\", \"deleteLights\")");
  4540.  
  4541.         menuItem 
  4542.             -label "Utilities"
  4543.             -annotation "Delete all Utility nodes"
  4544.             -command 
  4545.                 ("hyperShadePanelMenuCommand(\"" 
  4546.                     + $panel 
  4547.                     + "\", \"deleteUtilities\")");
  4548.  
  4549.         menuItem 
  4550.             -label "Cameras and Image Planes"
  4551.             -annotation "Delete all Cameras and Image Planes"
  4552.             -command 
  4553.                 ("hyperShadePanelMenuCommand(\"" 
  4554.                     + $panel 
  4555.                     + "\", \"deleteCamerasAndImagePlanes\")");
  4556.  
  4557.         menuItem 
  4558.             -label "Bake Sets"
  4559.             -annotation "Delete all Bake Sets"
  4560.             -command 
  4561.                 ("hyperShadePanelMenuCommand(\"" 
  4562.                     + $panel 
  4563.                     + "\", \"deleteBakeSets\")");
  4564.  
  4565.         setParent -menu ..;
  4566.  
  4567.     menuItem 
  4568.         -label "Revert Selected Swatches"
  4569.         -annotation 
  4570.             ("Revert Selected Swatches: Revert to default swatches for "
  4571.                 + "selected nodes")
  4572.         -command 
  4573.             ("hyperShadePanelMenuCommand(\"" 
  4574.                 + $panel 
  4575.                 + "\", \"revertSelectedSwatches\")");
  4576.  
  4577.     menuItem -divider true;
  4578.  
  4579.     menuItem -label "Select All by Type" -subMenu true;
  4580.  
  4581.         menuItem 
  4582.             -label "Shading Groups and Materials"
  4583.             -annotation "Select All Shading Groups and Materials"
  4584.             -command 
  4585.                 ("hyperShadePanelMenuCommand(\"" 
  4586.                     + $panel 
  4587.                     + "\", \"selectShadingGroupsAndMaterials\")");
  4588.  
  4589.         menuItem 
  4590.             -label "Textures"
  4591.             -annotation "Select All Textures"
  4592.             -command 
  4593.                 ("hyperShadePanelMenuCommand(\"" 
  4594.                     + $panel 
  4595.                     + "\", \"selectTextures\")");
  4596.  
  4597.         menuItem 
  4598.             -label "Lights"
  4599.             -annotation "Select All Lights"
  4600.             -command 
  4601.                 ("hyperShadePanelMenuCommand(\"" 
  4602.                     + $panel 
  4603.                     + "\", \"selectLights\")");
  4604.  
  4605.         menuItem 
  4606.             -label "Utilities"
  4607.             -annotation "Select All Utility nodes"
  4608.             -command 
  4609.                 ("hyperShadePanelMenuCommand(\"" 
  4610.                     + $panel 
  4611.                     + "\", \"selectUtilities\")");
  4612.  
  4613.         menuItem 
  4614.             -label "Cameras and Image Planes"
  4615.             -annotation "Select All Cameras and Image Planes"
  4616.             -command 
  4617.                 ("hyperShadePanelMenuCommand(\"" 
  4618.                     + $panel 
  4619.                     + "\", \"selectCamerasAndImagePlanes\")");
  4620.  
  4621.         menuItem 
  4622.             -label "Bake Sets"
  4623.             -annotation "Select All Bake Sets"
  4624.             -command 
  4625.                 ("hyperShadePanelMenuCommand(\"" 
  4626.                     + $panel 
  4627.                     + "\", \"selectBakeSets\")");
  4628.  
  4629.         setParent -menu ..;
  4630.  
  4631.     menuItem -divider true;
  4632.  
  4633.     menuItem -label "Duplicate" -subMenu true;
  4634.  
  4635.         menuItem 
  4636.             -label "Shading Network"
  4637.             -annotation 
  4638.                 ("Duplicate Shading Network: Duplicate selected node(s) "
  4639.                     + "including the input connection network(s)")
  4640.             -command 
  4641.                 ("hyperShadePanelMenuCommand(\"" 
  4642.                     + $panel 
  4643.                     + "\", \"duplicateShadingNetwork\")");
  4644.  
  4645.         menuItem 
  4646.             -label "Without Network"
  4647.             -annotation 
  4648.                 ("Duplicate Without Network: Duplicate only the selected "
  4649.                     + "node(s)")
  4650.             -command 
  4651.                 ("hyperShadePanelMenuCommand(\"" 
  4652.                     + $panel 
  4653.                     + "\", \"duplicateWithoutNetwork\")");
  4654.  
  4655.         menuItem 
  4656.             -label "With Connections to Network"
  4657.             -annotation 
  4658.                 ("Duplicate With Connections to Network: Duplicate "
  4659.                     + "selected node(s); connect new one(s) to input "
  4660.                     + "connection network")
  4661.             -command 
  4662.                 ("hyperShadePanelMenuCommand(\"" 
  4663.                     + $panel 
  4664.                     + "\", \"duplicateWithConnections\")");
  4665.  
  4666.         setParent -menu ..;
  4667.  
  4668.     menuItem -divider true;
  4669.  
  4670.     menuItem 
  4671.         -label 
  4672.             ("Convert to File Texture (Maya Software)")
  4673.         -annotation 
  4674.             ("Convert to File Texture: Create file texture(s) matching "
  4675.                 + "materials of selected object(s); select "
  4676.                 + "texture/material and surface(s)")
  4677.         -command 
  4678.             ("hyperShadePanelMenuCommand(\"" 
  4679.                 + $panel 
  4680.                 + "\", \"convertToFileTexture\")");
  4681.  
  4682.     menuItem 
  4683.         -label "Convert to File Texture Option Box" 
  4684.         -optionBox true 
  4685.         -command 
  4686.             ("hyperShadePanelMenuCommand(\"" 
  4687.                 + $panel 
  4688.                 + "\", \"convertToFileTextureOptionBox\")");
  4689. }
  4690.  
  4691. global proc hyperShadePanelBuildCreateMenu(string $panel, string $parent)
  4692. {
  4693.     //
  4694.     // Description:
  4695.     //    This procedure is called every time the Create menu is opened.
  4696.     //    This procedure builds the Create menu.
  4697.     //
  4698.  
  4699. //    menu -edit -deleteAllItems $parent;
  4700.  
  4701. //    setParent -menu $parent;    
  4702.  
  4703.     menuItem -label "Materials" -tearOff true -subMenu true; 
  4704.         buildCreateSubMenu(
  4705.             "shader/surface",
  4706.             "hyperShadePanelCreate \"shader\"");
  4707.     setParent -menu ..;
  4708.  
  4709.     menuItem -label "Volumetric Materials" -tearOff true -subMenu true; 
  4710.         buildCreateSubMenu(
  4711.             "shader/volume",
  4712.             "hyperShadePanelCreate \"shader\"");
  4713.     setParent -menu ..;
  4714.  
  4715.     menuItem -divider true;
  4716.  
  4717.     menuItem -label "2D Textures" -tearOff true -subMenu true;
  4718.         buildCreateSubMenu(
  4719.             "texture/2D",
  4720.             "hyperShadePanelCreate \"2dTexture\"");
  4721.         menuItem -divider true;
  4722.         radioMenuItemCollection;
  4723.         menuItem -label "2D Normal"
  4724.             -annotation "2D Normal: Create 2D textures"
  4725.             -radioButton 
  4726.                 (`optionVar -query create2dTextureType` == "normal")
  4727.             -command 
  4728.                 ("optionVar "
  4729.                     + "-stringValue create2dTextureType \"normal\";"
  4730.                     + "refreshCreateNodeUI();")
  4731.             textureAsNormalItem;
  4732.         menuItem -label "2D Projection"
  4733.             -annotation "2D Projection: Create 2D projection textures"
  4734.             -radioButton 
  4735.                 (`optionVar -query create2dTextureType` == "projection")
  4736.             -command 
  4737.                 ("optionVar "
  4738.                     + "-stringValue create2dTextureType \"projection\";"
  4739.                     + "refreshCreateNodeUI();")
  4740.             textureAsProjectionItem;
  4741.         menuItem -label "2D Stencil"
  4742.             -annotation "2D Stencil: Create 2D stencil textures"
  4743.             -radioButton 
  4744.                 (`optionVar -query create2dTextureType` == "stencil")
  4745.             -command 
  4746.                 ("optionVar "
  4747.                     + "-stringValue create2dTextureType \"stencil\";"
  4748.                     + "refreshCreateNodeUI();")
  4749.             textureAsStencilItem;
  4750.     setParent -menu ..;
  4751.  
  4752.     menuItem -label "3D Textures" -tearOff true -subMenu true;
  4753.         buildCreateSubMenu(
  4754.             "texture/3D",
  4755.             "hyperShadePanelCreate \"3dTexture\"");
  4756.     setParent -menu ..;
  4757.  
  4758.     menuItem -label "Environment Textures" -tearOff true -subMenu true;
  4759.         buildCreateSubMenu(
  4760.             "texture/environment",
  4761.             "hyperShadePanelCreate \"3dTexture\"");
  4762.     setParent -menu ..;
  4763.  
  4764.     buildCreateSubMenu(
  4765.         "texture/other",
  4766.         "hyperShadePanelCreate \"otherTexture\"");
  4767.  
  4768.     menuItem -divider true;
  4769.  
  4770.     menuItem -label "General Utilites" -tearOff true -subMenu true;
  4771.         buildCreateSubMenu(
  4772.             "utility/general",
  4773.             "hyperShadePanelCreate \"utility\"");
  4774.     setParent -menu ..;
  4775.     menuItem -label "Switch Utilites" -tearOff true -subMenu true;
  4776.         buildCreateSubMenu(
  4777.             "utility/switch",
  4778.             "hyperShadePanelCreate \"utility\"");
  4779.     setParent -menu ..;
  4780.     menuItem -label "Color Utilites" -tearOff true -subMenu true;
  4781.         buildCreateSubMenu(
  4782.             "utility/color",
  4783.             "hyperShadePanelCreate \"utility\"");
  4784.     setParent -menu ..;
  4785.     menuItem -label "Particle Utilites" -tearOff true -subMenu true;
  4786.         buildCreateSubMenu(
  4787.             "utility/particle",
  4788.             "hyperShadePanelCreate \"utility\"");
  4789.     setParent -menu ..;
  4790.     menuItem -label "Glow" -tearOff true -subMenu true;
  4791.         string $nodes[1];
  4792.         $nodes[0] = "opticalFX";
  4793.         buildCreateNodesSubMenu(
  4794.             $nodes,
  4795.             "hyperShadePanelCreate \"utility\"");
  4796.     setParent -menu ..;
  4797.  
  4798.     menuItem -divider true;
  4799.  
  4800.     menuItem -label "Lights" -tearOff true -subMenu true;
  4801.         buildCreateSubMenu(
  4802.             "light",
  4803.             "hyperShadePanelCreate \"light\"");
  4804.     setParent -menu ..;
  4805.     
  4806.     menuItem 
  4807.         -label "Camera"
  4808.         -annotation "Create a new Camera"
  4809.         -command ("hyperShadePanelCreate \"camera\" \"\"");
  4810.     if (`licenseCheck -m "edit" -typ "complete"`)
  4811.     {
  4812.         menuItem -label "Image Plane"
  4813.             -annotation "Create a new Image Plane"
  4814.             -command ("hyperShadePanelCreate \"node\" \"imagePlane\"");
  4815.     }
  4816.  
  4817.     menuItem -divider true;
  4818.  
  4819.     // We will only show custom shader UI if the user has their
  4820.     // MAYA_MRFM_SHOW_CUSTOM_SHADERS environment variable set to 1, and the
  4821.     // mental ray plugin is loaded.
  4822.     //
  4823.     int $showMentalRayCustomShaders = 0;
  4824.     int $mentalRayPluginLoaded = 0;
  4825.     
  4826.     if (`getenv MAYA_MRFM_SHOW_CUSTOM_SHADERS` == "1")
  4827.     {
  4828.         $showMentalRayCustomShaders = 1;
  4829.     }
  4830.  
  4831.     if (`pluginInfo -query -loaded Mayatomr`)
  4832.     {
  4833.         $mentalRayPluginLoaded = 1;
  4834.     }
  4835.  
  4836.     if ($showMentalRayCustomShaders && $mentalRayPluginLoaded)
  4837.     {
  4838.         mrHyperShadeCreateMenu_BuildMenu();
  4839.         menuItem -divider true;
  4840.     }
  4841.  
  4842.     menuItem
  4843.         -label "Create Render Node..."
  4844.         -annotation "Open Create Render Node window"
  4845.         -command 
  4846.             ("hyperShadePanelMenuCommand(\""
  4847.                 + $panel 
  4848.                 + "\", \"createNewNode\")");
  4849.     menuItem -divider true;
  4850.  
  4851.     menuItem -label "Create Options" -subMenu true;
  4852.  
  4853.         $includeShadingGroupItem = 
  4854.             `menuItem 
  4855.                 -label "Include Shading Group with Materials"
  4856.                 -checkBox true
  4857.                 -annotation 
  4858.                     ("Include Shading Group: If on, new materials are "
  4859.                         + "created with an associated shading group")
  4860.                 includeShadingGroupItem`;
  4861.         menuItem
  4862.             -edit
  4863.             -checkBox 
  4864.                 `optionVar -query createMaterialsWithShadingGroup` 
  4865.             -command 
  4866.                 ("optionVar -intValue createMaterialsWithShadingGroup "
  4867.                     + "`menuItem -query -checkBox " 
  4868.                     + $includeShadingGroupItem
  4869.                     + "`; refreshCreateNodeUI();")
  4870.             $includeShadingGroupItem;
  4871.  
  4872.         $createIncludePlacementItem = 
  4873.             `menuItem 
  4874.                 -label "Include Placement with Textures"
  4875.                 -checkBox true
  4876.                 -annotation 
  4877.                     ("Include Placement: If on, new textures are created "
  4878.                         + "with an associated placement node")
  4879.                 createIncludePlacementItem`;
  4880.         menuItem
  4881.             -edit
  4882.             -checkBox 
  4883.                 `optionVar -query createTexturesWithPlacement` 
  4884.             -command 
  4885.                 ("optionVar -intValue createTexturesWithPlacement "
  4886.                     + "`menuItem -query -checkBox " 
  4887.                     + $createIncludePlacementItem
  4888.                     + "`; refreshCreateNodeUI();")
  4889.             $createIncludePlacementItem;
  4890.  
  4891.     //setParent ..;
  4892.     setParent -menu ..;
  4893. }
  4894.  
  4895. global proc hyperShadePanelBuildCreateBarOptionsMenu(
  4896.     string $panel,
  4897.     string $menuParent)
  4898. {
  4899.     //
  4900.     // Description:
  4901.     //    This procedure is called every time the Create-> Create Bar menu
  4902.     //    item in the hypershade panel menu is selected.
  4903.     //    This procedure creates the menu items which will appear in that menu.
  4904.     //
  4905.  
  4906.     setParent $panel;
  4907.     setParent -menu $menuParent;
  4908.     menu
  4909.         -edit
  4910.         -deleteAllItems
  4911.         $menuParent;
  4912.  
  4913.         string $renderCreateBarUI = renderCreateBarUIName($panel);
  4914.         int $managed = renderCreateBarUIIsManaged($renderCreateBarUI); 
  4915.  
  4916.         menuItem
  4917.             -label "Show Create Bar"
  4918.             -checkBox $managed
  4919.             -command
  4920.                 ("hyperShadePanelMenuCommand(\"" 
  4921.                     + $panel 
  4922.                     + "\", \"toggleRenderCreateBar\")");
  4923.         
  4924.         menuItem -divider true;
  4925.  
  4926.         radioMenuItemCollection;
  4927.  
  4928.         string $style = `optionVar -query renderCreateBarStyle`;
  4929.  
  4930.         menuItem 
  4931.             -label "Display Icons and Text"
  4932.             -radioButton ($style == "iconsAndText")
  4933.             -annotation
  4934.                 ("Display Icons and Text: Configure the Create Bar to display "
  4935.                     + "icons and text")
  4936.             -command 
  4937.                 ("hyperShadePanelMenuCommand(\"" 
  4938.                     + $panel 
  4939.                     + "\", \"createBarDisplayIconsAndText\")");
  4940.         menuItem 
  4941.             -label "Display Icons Only"
  4942.             -radioButton ($style == "iconsOnly")
  4943.             -annotation
  4944.                 ("Display Icons Only: Configure the Create Bar to display "
  4945.                     + "only icons (no text)")
  4946.             -command 
  4947.                 ("hyperShadePanelMenuCommand(\"" 
  4948.                     + $panel 
  4949.                     + "\", \"createBarDisplayIconsOnly\")");
  4950.  
  4951.     setParent -menu ..;
  4952. }
  4953.  
  4954.  
  4955. global proc hyperShadePanelBuildTabOptionsMenu(
  4956.     string $panel,
  4957.     string $menuParent)
  4958. {
  4959.     //
  4960.     // Description:
  4961.     //    This procedure is called every time the Tabs->Current Tab Options menu
  4962.     //    item in the hypershade panel menu is selected.
  4963.     //    This procedure creates the menu items which will appear in that menu,
  4964.     //    such that they are the appropriate ones for the active tab type.
  4965.     //
  4966.  
  4967.     setParent $panel;
  4968.     setParent -menu $menuParent;
  4969.     menu
  4970.         -edit
  4971.         -deleteAllItems
  4972.         $menuParent;
  4973.  
  4974.     string $activeTab = activeTab($panel);
  4975.  
  4976.     if (isDiskTab($activeTab))
  4977.     {
  4978.         string $libraryUI = lookupComponentName($activeTab);
  4979.         int $onlyDirectoriesShown = false;
  4980.         int $onlyFilesShown = false;
  4981.         int $bothShown = false;
  4982.  
  4983.         if (
  4984.                 libraryUIDirectoriesShown($libraryUI)
  4985.             &&    libraryUIFilesShown($libraryUI))
  4986.         {
  4987.             $bothShown = true;
  4988.         }
  4989.         else if (libraryUIDirectoriesShown($libraryUI))
  4990.         {
  4991.             $onlyDirectoriesShown = true;
  4992.         }
  4993.         else if (libraryUIFilesShown($libraryUI))
  4994.         {
  4995.             $onlyFilesShown = true;
  4996.         }
  4997.         
  4998.         radioMenuItemCollection;
  4999.         menuItem 
  5000.             -label "Show Directories Only"
  5001.             -radioButton $onlyDirectoriesShown
  5002.             -annotation
  5003.                 ("Show Directories Only: Hide the section of the active tab "
  5004.                     + "which displays files")
  5005.             -command 
  5006.                 ("hyperShadePanelMenuCommand(\"" 
  5007.                     + $panel 
  5008.                     + "\", \"showDirectoriesOnly\")");
  5009.         menuItem 
  5010.             -label "Show Files Only"
  5011.             -radioButton $onlyFilesShown
  5012.             -annotation
  5013.                 ("Show Files Only: Hide the section of the active tab "
  5014.                     + "which displays directories")
  5015.             -command 
  5016.                 ("hyperShadePanelMenuCommand(\"" 
  5017.                     + $panel 
  5018.                     + "\", \"showFilesOnly\")");
  5019.         menuItem 
  5020.             -label "Show Both"
  5021.             -radioButton $bothShown
  5022.             -annotation
  5023.                 ("Show Both: Show both sections of the active tab "
  5024.                     + "(directories and files)")
  5025.             -command 
  5026.                 ("hyperShadePanelMenuCommand(\"" 
  5027.                     + $panel 
  5028.                     + "\", \"showDirectoriesAndFiles\")");
  5029.         menuItem -divider true;
  5030.         menuItem
  5031.             -label "Refresh File Listing"
  5032.             -annotation
  5033.                 ("Refresh File Listing: Refresh the display of files on disk "
  5034.                     + "to reflect newly added or removed files")
  5035.             -command
  5036.                 ("hyperShadePanelMenuCommand(\""
  5037.                     + $panel 
  5038.                     + "\", \"refreshFileListing\")");
  5039.         menuItem
  5040.             -label "Refresh Selected Swatches"
  5041.             -annotation
  5042.                 ("Refresh Selected Swatches: Refresh the selected swatches "
  5043.                     + "to reflect changes made to the files")
  5044.             -command
  5045.                 ("hyperShadePanelMenuCommand(\""
  5046.                     + $panel 
  5047.                     + "\", \"refreshSelectedSwatches\")");
  5048.         menuItem
  5049.             -label "Refresh All Swatches"
  5050.             -annotation
  5051.                 ("Refresh All Swatches: Refresh all swatches "
  5052.                     + "to reflect changes made to the files")
  5053.             -command
  5054.                 ("hyperShadePanelMenuCommand(\""
  5055.                     + $panel 
  5056.                     + "\", \"refreshAllSwatches\")");
  5057.         menuItem -divider true;
  5058.         menuItem
  5059.             -label "Generate Swatch Files for Current Images"
  5060.             -annotation
  5061.                 ("Generate Swatch Files for Current Images: "
  5062.                     + "Save the swatches of the currently displayed files "
  5063.                     + "to disk so this directory can be opened faster")
  5064.             -command
  5065.                 ("hyperShadePanelMenuCommand(\""
  5066.                     + $panel 
  5067.                     + "\", \"saveSwatchesToDisk\")");
  5068.     }
  5069.     else
  5070.     {
  5071.         menuItem
  5072.             -label "No options available"
  5073.             -enable false;
  5074.     }
  5075.  
  5076.     setParent -menu ..;
  5077. }
  5078.  
  5079. global proc hyperShadePanelGraphCommand(
  5080.     string $panel,
  5081.     string $command)
  5082. {
  5083.     // Determine which graph tab (work area) would be the most appropriate
  5084.     // tab to perform this operation in. This will be called the target tab.
  5085.     //
  5086.     string $targetTab;
  5087.  
  5088.     $targetTab = targetGraphTab($panel);
  5089.  
  5090.     // Get the name of the hypershade in the target graph tab so that we
  5091.     // can graph into it.
  5092.     //
  5093.     string $graphUI;
  5094.  
  5095.     $graphUI = lookupComponentName($targetTab);
  5096.  
  5097.     // Select the tab so the user can see the graph.
  5098.     //
  5099.     selectTab($panel, $targetTab);
  5100.  
  5101.     if ($command == "graphMaterials")
  5102.     {
  5103.         if (size(`ls -sl`) != 0)
  5104.         {
  5105.             graphUIGraphMaterials($graphUI);
  5106.         }
  5107.         else
  5108.         {
  5109.             warning("Nothing is selected.");
  5110.         }
  5111.     }
  5112.     else if ($command == "clearGraph")
  5113.     {
  5114.         graphUIClearGraph($graphUI);
  5115.     }
  5116.     else if ($command == "showUpAndDownstream")
  5117.     {
  5118.         if (size(`ls -sl`) != 0)
  5119.         {
  5120.             graphUIShowUpAndDownstream($graphUI);
  5121.         }
  5122.         else
  5123.         {
  5124.             warning("Nothing is selected.");
  5125.         }
  5126.     }
  5127.     else if ($command == "showUpstream")
  5128.     {
  5129.         if (size(`ls -sl`) != 0)
  5130.         {
  5131.             graphUIShowUpstream($graphUI);
  5132.         }
  5133.         else
  5134.         {
  5135.             warning("Nothing is selected.");
  5136.         }
  5137.     }
  5138.     else if ($command == "showDownstream")
  5139.     {
  5140.         if (size(`ls -sl`) != 0)
  5141.         {
  5142.             graphUIShowDownstream($graphUI);
  5143.         }
  5144.         else
  5145.         {
  5146.             warning("Nothing is selected.");
  5147.         }
  5148.     }
  5149.     else if ($command == "rearrangeGraph")
  5150.     {
  5151.         graphUIRearrangeGraph($graphUI);
  5152.     }
  5153.     else if ($command == "showPreviousGraph")
  5154.     {
  5155.         graphUIShowPreviousGraph($graphUI);
  5156.     }
  5157.     else if ($command == "showNextGraph")
  5158.     {
  5159.         graphUIShowNextGraph($graphUI);
  5160.     }
  5161.     else if ($command == "addSelected")
  5162.     {
  5163.         graphUIAddSelected($graphUI);
  5164.     }
  5165.     else if ($command == "removeSelected")
  5166.     {
  5167.         graphUIRemoveSelected($graphUI);
  5168.     }
  5169.  
  5170.     refreshToolbar($panel);
  5171.     refreshGraphMenu($panel);
  5172. }
  5173.  
  5174. global proc hyperShadePanelMenuCommand(
  5175.     string $panel,
  5176.     string $command)
  5177. {
  5178.     //
  5179.     // Description:
  5180.     //    This procedure is called whenever a menu item is chosen from the
  5181.     //    hypershade panel menu.
  5182.     //    This procedure is the single global procedure entry point to all
  5183.     //    functionality invoked by the menu items. This avoids cluttering the
  5184.     //    global procedure namespace with a global procedure for each menu item.
  5185.     //    This procedure causes the expected action to be performed. Typically
  5186.     //    this will mean calling some local procedure within this file to perform
  5187.     //    the action the user expects when they choose the menu item.
  5188.     //
  5189.  
  5190.     if ($command == "")
  5191.     {
  5192.     }
  5193.     else if ($command == "import")
  5194.     {
  5195.         Import;
  5196.     }
  5197.     else if (
  5198.             ($command == "importSelectedSceneFiles")
  5199.         ||    ($command == "importSelectedImageFilesAsNormal")
  5200.         ||    ($command == "importSelectedImageFilesAsProjection")
  5201.         ||    ($command == "importSelectedImageFilesAsStencil"))
  5202.     {
  5203.         string $activeTab = activeTab($panel);
  5204.         if (isDiskTab($activeTab))
  5205.         {
  5206.             string $libraryUI;
  5207.             $libraryUI = lookupComponentName($activeTab);
  5208.  
  5209.             string $filesVisor;
  5210.             $filesVisor = libraryUIFilesVisor($libraryUI);
  5211.  
  5212.             string $filesToImport[];
  5213.             $filesToImport = `visor -query -selectedGadgets $filesVisor`;
  5214.  
  5215.             int $asProjection;
  5216.             int $asStencil;
  5217.             int $withPlacement;
  5218.  
  5219.             if ($command == "importSelectedImageFilesAsNormal")
  5220.             {
  5221.                 $asProjection = false;
  5222.                 $asStencil = false;
  5223.             }
  5224.             else if ($command == "importSelectedImageFilesAsProjection")
  5225.             {
  5226.                 $asProjection = true;
  5227.                 $asStencil = false;
  5228.             }
  5229.             else if ($command == "importSelectedImageFilesAsStencil")
  5230.             {
  5231.                 $asProjection = false;
  5232.                 $asStencil = true;
  5233.             }
  5234.  
  5235.             $withPlacement =
  5236.                 (`optionVar -query createTexturesWithPlacement`);
  5237.  
  5238.             int $i;
  5239.  
  5240.             for ($i = 0; $i < size($filesToImport); $i++)
  5241.             {
  5242.                 string $fileTypesArray[] = 
  5243.                     `file -query -type $filesToImport[$i]`;
  5244.                 string $fileType = $fileTypesArray[0];
  5245.  
  5246.                 if (
  5247.                         ($command == "importSelectedSceneFiles") 
  5248.                     &&     (    ($fileType == "mayaBinary") 
  5249.                         ||     ($fileType == "mayaPLE")
  5250.                         ||     ($fileType == "mayaAscii")))
  5251.                 {
  5252.                     file -import $filesToImport[$i];
  5253.                     print("// Imported: " + $filesToImport[$i] + "\n");
  5254.                 }
  5255.                 else if ($fileType == "image")
  5256.                 {
  5257.                     importImageFile(
  5258.                         $filesToImport[$i], 
  5259.                         $asProjection,
  5260.                         $asStencil,
  5261.                         $withPlacement);
  5262.                 }
  5263.             }
  5264.         }
  5265.     }
  5266.     else if ($command == "exportSelectedNetwork")
  5267.     {
  5268.         global string        $gv_operationMode;
  5269.         string                $filetype;
  5270.         string                $ws = `workspace -q -fn`;
  5271.  
  5272.         // Old projects saved their shaders in a directory called "lights".
  5273.         // New projects save both lights and shaders in a directory called
  5274.         // "shaders". We have to continue to specify that the shading network
  5275.         // be stored in whatever directory is used to store lights, just in
  5276.         // case this is an old project.
  5277.         //
  5278.         setWorkingDirectory $ws "image" "lights";
  5279.  
  5280.         if (`optionVar -exists defaultFileExportActiveType`) 
  5281.         {
  5282.             $filetype = `optionVar -q defaultFileExportActiveType`;
  5283.         }
  5284.         else 
  5285.         {
  5286.             $filetype = "mayaBinary";
  5287.         }
  5288.  
  5289.         $gv_operationMode = "ExportActive";
  5290.         
  5291.         // Open the file browser to export the selection
  5292.         //
  5293.         fileBrowser "pv_performAction" "Export Selection" $filetype 1;
  5294.     }
  5295.     else if ($command == "toggleRenderCreateBar")
  5296.     {
  5297.         string $renderCreateBarUI = renderCreateBarUIName($panel);
  5298.         int $manage = !(renderCreateBarUIIsManaged($renderCreateBarUI)); 
  5299.         renderCreateBarUIManage($renderCreateBarUI, $manage);
  5300.         optionVar -intValue hyperShadePanelCreateBarShown $manage;
  5301.  
  5302.         int $iconsAndTextWidth = 
  5303.             `optionVar -query hyperShadePanelCreateBarIconsAndTextWidth`;
  5304.  
  5305.         global int $gRenderCreateBarIconsOnlyWidth;
  5306.  
  5307.         string $style = `optionVar -query renderCreateBarStyle`;
  5308.         int $createBarWidth;
  5309.         
  5310.         if ($style == "iconsAndText")
  5311.         {
  5312.             $createBarWidth = $iconsAndTextWidth;
  5313.         }
  5314.         else
  5315.         {
  5316.             $createBarWidth = $gRenderCreateBarIconsOnlyWidth;
  5317.         }
  5318.  
  5319.         if (!$manage)
  5320.         {
  5321.             $createBarWidth = 1;
  5322.         }
  5323.  
  5324.         setParent $panel;
  5325.         formLayout
  5326.             -edit
  5327.             -af paneArrangement    left $createBarWidth
  5328.             mainForm;
  5329.  
  5330.         refreshCreateMenu($panel);
  5331.     }
  5332.     else if ($command == "createBarDisplayIconsAndText")
  5333.     {
  5334.         string $style = `optionVar -query renderCreateBarStyle`;
  5335.  
  5336.         if ($style != "iconsAndText")
  5337.         {
  5338.             // The UI is not already showing icons and text, so we will change
  5339.             // it so that it is.
  5340.             //
  5341.             optionVar -stringValue renderCreateBarStyle "iconsAndText";
  5342.             string $renderCreateBarUI = renderCreateBarUIName($panel);
  5343.  
  5344.             // Delete the existing icons only UI
  5345.             //
  5346.             deleteUI $renderCreateBarUI;
  5347.  
  5348.             // Hide the section of the hyperShadePanel which contains the
  5349.             // create bar until it has finished building
  5350.             //
  5351.             setParent $panel;
  5352.             int $iconsAndTextWidth = 
  5353.                 `optionVar -query hyperShadePanelCreateBarIconsAndTextWidth`;
  5354.  
  5355.             formLayout
  5356.                 -edit
  5357.                 -af paneArrangement    left 1
  5358.                 mainForm;
  5359.  
  5360.             // Manage the increase/decrease create bar size buttons since it
  5361.             // should be visible when the create bar is in icons and text mode.
  5362.             //
  5363.             formLayout
  5364.                 -edit
  5365.                 -manage true
  5366.                 createBarSizeButtonsForm;
  5367.  
  5368.             // Build the new create bar
  5369.             //
  5370.             string $createBarForm = `setParent createBarForm`;
  5371.             renderCreateBarUI($createBarForm);
  5372.  
  5373.             // Show the create bar again
  5374.             //
  5375.             formLayout
  5376.                 -edit
  5377.                 -af paneArrangement    left $iconsAndTextWidth
  5378.                 mainForm;
  5379.         }
  5380.     }
  5381.     else if ($command == "createBarDisplayIconsOnly")
  5382.     {
  5383.         string $style = `optionVar -query renderCreateBarStyle`;
  5384.  
  5385.         if ($style != "iconsOnly")
  5386.         {
  5387.             // The UI is not already showing icons only, so we will change
  5388.             // it so that it is.
  5389.             //
  5390.             optionVar -stringValue renderCreateBarStyle "iconsOnly";
  5391.             string $renderCreateBarUI = renderCreateBarUIName($panel);
  5392.  
  5393.             // Delete the existing icons only UI
  5394.             //
  5395.             deleteUI $renderCreateBarUI;
  5396.  
  5397.             // Hide the section of the hyperShadePanel which contains the
  5398.             // create bar until it has finished building
  5399.             //
  5400.             setParent $panel;
  5401.             global int $gRenderCreateBarIconsOnlyWidth;
  5402.             formLayout
  5403.                 -edit
  5404.                 -af paneArrangement    left 1
  5405.                 mainForm;
  5406.  
  5407.             // Hide the increase/decrease create bar size buttons because the
  5408.             // size of the create bar shouldn't be changed when in iconsOnly
  5409.             // mode.
  5410.             //
  5411.             formLayout
  5412.                 -edit
  5413.                 -manage false
  5414.                 createBarSizeButtonsForm;
  5415.  
  5416.             // Build the new create bar
  5417.             //
  5418.             string $createBarForm = `setParent createBarForm`;
  5419.             renderCreateBarUI($createBarForm);
  5420.  
  5421.             // Show the create bar again
  5422.             //
  5423.             formLayout
  5424.                 -edit
  5425.                 -af paneArrangement    left $gRenderCreateBarIconsOnlyWidth
  5426.                 mainForm;
  5427.         }
  5428.     }
  5429.     else if ($command == "createNewNode")
  5430.     {
  5431.         createRenderNode("-all", "", "");
  5432.     }
  5433.     else if ($command == "duplicateShadingNetwork")
  5434.     {
  5435.         hyperShade -duplicate;
  5436.     }
  5437.     else if ($command == "duplicateWithoutNetwork")
  5438.     {
  5439.         duplicate;
  5440.     }
  5441.     else if ($command == "duplicateWithConnections")
  5442.     {
  5443.         duplicate -inputConnections;
  5444.     }
  5445.     else if ($command == "deleteShadingGroupsAndMaterials")
  5446.     {
  5447.         string $cmd;
  5448.         string $items[];
  5449.         string $item;
  5450.  
  5451.         $cmd = "delete ";
  5452.         $items = `lsThroughFilter DefaultShadingGroupsAndMaterialsFilter`;
  5453.         
  5454.         if (size($items) > 0)
  5455.         {
  5456.             for ($item in $items)
  5457.             {
  5458.                 $cmd = ($cmd + " " + $item);
  5459.             }
  5460.             eval $cmd;
  5461.         }
  5462.     }
  5463.     else if ($command == "deleteTextures")
  5464.     {
  5465.         string $cmd;
  5466.         string $items[];
  5467.         string $item;
  5468.  
  5469.         $cmd = "delete ";
  5470.         $items = `lsThroughFilter DefaultTexturesFilter`;
  5471.         
  5472.         if (size($items) > 0)
  5473.         {
  5474.             for ($item in $items)
  5475.             {
  5476.                 $cmd = ($cmd + " " + $item);
  5477.             }
  5478.             eval $cmd;
  5479.         }
  5480.     }
  5481.     else if ($command == "deleteLights")
  5482.     {
  5483.         string $cmd;
  5484.         string $items[];
  5485.         string $item;
  5486.  
  5487.         $cmd = "delete ";
  5488.         $items = `lsThroughFilter DefaultAllLightsFilter`;
  5489.         
  5490.         if (size($items) > 0)
  5491.         {
  5492.             for ($item in $items)
  5493.             {
  5494.                 $cmd = ($cmd + " " + $item);
  5495.             }
  5496.             eval $cmd;
  5497.         }
  5498.     }
  5499.     else if ($command == "deleteUtilities")
  5500.     {
  5501.         string $cmd;
  5502.         string $items[];
  5503.         string $item;
  5504.  
  5505.         $cmd = "delete ";
  5506.         $items = `lsThroughFilter DefaultRenderUtilitiesFilter`;
  5507.         
  5508.         if (size($items) > 0)
  5509.         {
  5510.             for ($item in $items)
  5511.             {
  5512.                 $cmd = ($cmd + " " + $item);
  5513.             }
  5514.             eval $cmd;
  5515.         }
  5516.     }
  5517.     else if ($command == "deleteCamerasAndImagePlanes")
  5518.     {
  5519.         string $cmd;
  5520.         string $items[];
  5521.         string $item;
  5522.  
  5523.         $cmd = "delete ";
  5524.         $items = `lsThroughFilter DefaultCameraShapesImagePlanesFilter`;
  5525.         
  5526.         if (size($items) > 0)
  5527.         {
  5528.             for ($item in $items)
  5529.             {
  5530.                 $cmd = ($cmd + " " + $item);
  5531.             }
  5532.             eval $cmd;
  5533.         }
  5534.     }
  5535.     else if ($command == "deleteBakeSets")
  5536.     {
  5537.         string $cmd;
  5538.         string $items[];
  5539.         string $item;
  5540.  
  5541.         $cmd = "delete ";
  5542.         $items = `lsThroughFilter DefaultBakeSetsFilter`;
  5543.         
  5544.         if (size($items) > 0)
  5545.         {
  5546.             for ($item in $items)
  5547.             {
  5548.                 $cmd = ($cmd + " " + $item);
  5549.             }
  5550.             eval $cmd;
  5551.         }
  5552.     }
  5553.     else if ($command == "selectShadingGroupsAndMaterials")
  5554.     {
  5555.         select 
  5556.             -noExpand 
  5557.             -replace
  5558.             `lsThroughFilter DefaultShadingGroupsAndMaterialsFilter`;
  5559.     }
  5560.     else if ($command == "selectTextures")
  5561.     {
  5562.         select 
  5563.             -noExpand
  5564.             -replace 
  5565.             `lsThroughFilter DefaultTexturesFilter`;
  5566.     }
  5567.     else if ($command == "selectLights")
  5568.     {
  5569.         select 
  5570.             -noExpand
  5571.             -replace 
  5572.             `lsThroughFilter DefaultAllLightsFilter`; 
  5573.     }
  5574.     else if ($command == "selectUtilities")
  5575.     {
  5576.         select 
  5577.             -noExpand 
  5578.             -replace
  5579.             `lsThroughFilter DefaultRenderUtilitiesFilter`; 
  5580.     }
  5581.     else if ($command == "selectCamerasAndImagePlanes")
  5582.     {
  5583.         select 
  5584.             -noExpand
  5585.             -replace 
  5586.             `lsThroughFilter DefaultCameraShapesImagePlanesFilter`; 
  5587.     }
  5588.     else if ($command == "selectBakeSets")
  5589.     {
  5590.         select 
  5591.             -noExpand
  5592.             -replace 
  5593.             `lsThroughFilter DefaultBakeSetsFilter`; 
  5594.     }
  5595.     else if ($command == "revertSelectedSwatches")
  5596.     {
  5597.         hyperShade -resetSwatch;
  5598.     }
  5599.     else if ($command == "convertToFileTexture")
  5600.     {
  5601.         performConvertSolidTx false false;
  5602.     }
  5603.     else if ($command == "convertToFileTextureOptionBox")
  5604.     {
  5605.         performConvertSolidTx true false;
  5606.     }
  5607.     else if ($command == "delete")
  5608.     {
  5609.         delete;    
  5610.     }
  5611.     else if ($command == "deleteUnusedNodes")
  5612.     {
  5613.         MLdeleteUnused;    
  5614.     }
  5615.     else if ($command == "createNewTab")
  5616.     {
  5617.         createNewTab($panel);
  5618.     }
  5619.     else if ($command == "moveTabUp")
  5620.     {
  5621.         moveTab($panel, "up");
  5622.     }
  5623.     else if ($command == "moveTabDown")
  5624.     {
  5625.         moveTab($panel, "down");
  5626.     }
  5627.     else if ($command == "moveTabLeft")
  5628.     {
  5629.         moveTab($panel, "left");
  5630.     }
  5631.     else if ($command == "moveTabRight")
  5632.     {
  5633.         moveTab($panel, "right");
  5634.     }
  5635.     else if ($command == "renameTab")
  5636.     {
  5637.         renameTab($panel);
  5638.     }
  5639.     else if ($command == "showTopTabsOnly")
  5640.     {
  5641.         showTopTabsOnly($panel);
  5642.     }
  5643.     else if ($command == "showBottomTabsOnly")
  5644.     {
  5645.         showBottomTabsOnly($panel);
  5646.     }
  5647.     else if ($command == "showTopAndBottomTabs")
  5648.     {
  5649.         showTopAndBottomTabs($panel);
  5650.     }
  5651.     else if ($command == "removeTab")
  5652.     {
  5653.         string $confirm = 
  5654.             `confirmDialog
  5655.                 -title "Confirm Remove Current Tab"
  5656.                 -message 
  5657.                     ("Are you sure you want to remove the \""
  5658.                         + activeTabLabel($panel)
  5659.                         + "\" tab?")
  5660.                 -button "Yes"
  5661.                 -button "No"
  5662.                 -defaultButton "No"
  5663.                 -cancelButton "No"`;
  5664.         if ($confirm == "Yes")
  5665.         {
  5666.             removeActiveTab($panel);
  5667.         }
  5668.     }
  5669.     else if ($command == "revertToDefaultTabs")
  5670.     {
  5671.         string $confirm = 
  5672.             `confirmDialog
  5673.                 -title "Confirm Revert to Default Tabs"
  5674.                 -message 
  5675.                     ("This operation will remove all tabs from the\n"
  5676.                         + "Hypershade layout except Materials, Textures\n"
  5677.                         + "Utilities, Lights, Cameras, Bake Sets, Projects, Work Area\n"
  5678.                         + "and Shader Library (if installed).\n"
  5679.                         + "Are you sure you want to revert to default tabs?\n")
  5680.                 -button "Yes"
  5681.                 -button "No"
  5682.                 -defaultButton "No"
  5683.                 -cancelButton "No"`;
  5684.         if ($confirm == "Yes")
  5685.         {
  5686.             revertToDefaultTabs($panel);
  5687.         }
  5688.     }
  5689.     else if ($command == "showDirectoriesOnly")
  5690.     {
  5691.         string $activeTab = activeTab($panel);
  5692.         if (isDiskTab($activeTab))
  5693.         {
  5694.             string $libraryUI = lookupComponentName($activeTab);
  5695.             libraryUIShowDirectoriesOnly($libraryUI);
  5696.             string $tabOptionVar = lookupTabOptionVar($activeTab);
  5697.             updateTabOptionVar($tabOptionVar, $activeTab);
  5698.         }
  5699.     }
  5700.     else if ($command == "showFilesOnly")
  5701.     {
  5702.         string $activeTab = activeTab($panel);
  5703.         if (isDiskTab($activeTab))
  5704.         {
  5705.             string $libraryUI = lookupComponentName($activeTab);
  5706.             libraryUIShowFilesOnly($libraryUI);
  5707.             string $tabOptionVar = lookupTabOptionVar($activeTab);
  5708.             updateTabOptionVar($tabOptionVar, $activeTab);
  5709.         }
  5710.     }
  5711.     else if ($command == "showDirectoriesAndFiles")
  5712.     {
  5713.         string $activeTab = activeTab($panel);
  5714.         if (isDiskTab($activeTab))
  5715.         {
  5716.             string $libraryUI = lookupComponentName($activeTab);
  5717.             libraryUIShowDirectoriesAndFiles($libraryUI);
  5718.             string $tabOptionVar = lookupTabOptionVar($activeTab);
  5719.             updateTabOptionVar($tabOptionVar, $activeTab);
  5720.         }
  5721.     }
  5722.     else if ($command == "refreshFileListing")
  5723.     {
  5724.         string $activeTab = activeTab($panel);
  5725.         if (isDiskTab($activeTab))
  5726.         {
  5727.             string $libraryUI = lookupComponentName($activeTab);
  5728.             libraryUIRefreshFileListing($libraryUI);
  5729.         }
  5730.     }
  5731.     else if ($command == "refreshSelectedSwatches")
  5732.     {
  5733.         string $activeTab = activeTab($panel);
  5734.         if (isDiskTab($activeTab))
  5735.         {
  5736.             string $libraryUI = lookupComponentName($activeTab);
  5737.             libraryUIRefreshSelectedSwatches($libraryUI);
  5738.         }
  5739.     }
  5740.     else if ($command == "refreshAllSwatches")
  5741.     {
  5742.         string $activeTab = activeTab($panel);
  5743.         if (isDiskTab($activeTab))
  5744.         {
  5745.             string $libraryUI = lookupComponentName($activeTab);
  5746.             libraryUIRefreshAllSwatches($libraryUI);
  5747.         }
  5748.     }
  5749.     else if ($command == "saveSwatchesToDisk")
  5750.     {
  5751.         string $activeTab = activeTab($panel);
  5752.         if (isDiskTab($activeTab))
  5753.         {
  5754.             string $libraryUI = lookupComponentName($activeTab);
  5755.             libraryUISaveSwatchesToDisk($libraryUI);
  5756.         }
  5757.     }
  5758.     else if ($command == "frameSelected")
  5759.     {
  5760.         string $activeTab = activeTab($panel);
  5761.         string $component = lookupComponentName($activeTab);
  5762.         string $editor;
  5763.  
  5764.         if (isGraphTab($activeTab))
  5765.         {
  5766.             $editor = graphUIHypershadeName($component);
  5767.         }
  5768.         else if (isSceneTab($activeTab))
  5769.         {
  5770.             $editor = collectionUIHypershadeName($component);
  5771.         }
  5772.         else if (isDiskTab($activeTab))
  5773.         {
  5774.             $editor = libraryUIFilesVisor($component);
  5775.         }
  5776.  
  5777.         hyperGraph -edit -frame $editor;
  5778.     }
  5779.     else if ($command == "frameAll")
  5780.     {
  5781.         string $activeTab = activeTab($panel);
  5782.         string $component = lookupComponentName($activeTab);
  5783.         string $editor;
  5784.  
  5785.         if (isGraphTab($activeTab))
  5786.         {
  5787.             $editor = graphUIHypershadeName($component);
  5788.         }
  5789.         else if (isSceneTab($activeTab))
  5790.         {
  5791.             $editor = collectionUIHypershadeName($component);
  5792.         }
  5793.         else if (isDiskTab($activeTab))
  5794.         {
  5795.             $editor = libraryUIFilesVisor($component);
  5796.         }
  5797.  
  5798.         hyperGraph -edit -frameGraph $editor;
  5799.     }
  5800.     else if ($command == "keepSwatchesAtCurrentResolution")
  5801.     {
  5802.         hyperShade 
  5803.             -fixRenderSize `optionVar -query keepSwatchesAtCurrentResolution`;
  5804.     }
  5805.     else
  5806.     {
  5807.         error
  5808.             -showLineNumber true
  5809.             ("Command not yet implemented: " + $command);
  5810.     }
  5811. }
  5812.  
  5813. global proc hyperShadePanelGraphNodeNetwork(
  5814.     string $panel,
  5815.     string $hypershade,
  5816.     string $node)
  5817. {
  5818.     //
  5819.     // Description:
  5820.     //    This procedure is called from the RMB popup menu of a node in a
  5821.     //    scene or graph tab in the shader editor.
  5822.     //    This method determines what tab the RMB menu is being invoked from,
  5823.     //    what tab the graph should be displayed in, and displays the graph.
  5824.     //
  5825.  
  5826.     //
  5827.     // To determine what tab the RMB is being invoked from is a bit ugly. We
  5828.     // will search up the parent structure from the hypershade which has been
  5829.     // provided, looking for firstPaneTabs or secondPaneTabs. We keep track of
  5830.     // the layout we just came from so that when we find firstPaneTabs or
  5831.     // secondPaneTabs we know what tab contained the hypershade.
  5832.     //
  5833.  
  5834.     setParent $panel;
  5835.     string $firstPaneTabs = `setParent firstPaneTabs`;
  5836.     setParent $panel;
  5837.     string $secondPaneTabs = `setParent secondPaneTabs`;
  5838.  
  5839.     string $parent = `hyperGraph -query -parent $hypershade`;
  5840.     string $child;
  5841.  
  5842.     setParent $parent;
  5843.  
  5844.     while (($parent != $firstPaneTabs) && ($parent != $secondPaneTabs))
  5845.     {
  5846.         $child = $parent;
  5847.         $parent = `setParent ..`;
  5848.         if ($parent == "") break;
  5849.     }
  5850.  
  5851.     if (($parent != $firstPaneTabs) && ($parent != $secondPaneTabs))
  5852.     {
  5853.         error
  5854.             -showLineNumber true
  5855.             ("hyperShadePanelGraphNodeNetwork invoked from outside "
  5856.                 + "of Hypershade.");
  5857.     }
  5858.  
  5859.     // When we get to here, the name of the tab from which the menu was invoked
  5860.     // is stored in $child. To make things a little easier to understand, we
  5861.     // will store that name in $activeTab.
  5862.     //
  5863.     string $activeTab = $child;
  5864.     string $tabType = lookupTabType($activeTab);
  5865.     
  5866.     if (($tabType == "graph") || ($tabType == "protected graph"))
  5867.     {
  5868.         // The user is already in a graph, so we will graph the network in this
  5869.         // graph.
  5870.         //
  5871.         if (`optionVar -query hsClearBeforeGraphing` == 1)
  5872.         {
  5873.             hyperShade -clearWorkArea $hypershade;
  5874.         }
  5875.  
  5876.         hyperShade -shaderNetwork $node $hypershade;
  5877.  
  5878.         if (`optionVar -query hsClearBeforeGraphing` == 1)
  5879.         {
  5880.             hyperGraph -edit -frameGraph $hypershade;
  5881.         }
  5882.     }
  5883.     else if ($tabType == "scene")
  5884.     {
  5885.         // The user is in a scene graph, so we will graph the network in the
  5886.         // protected graph (default Work Area)
  5887.         //
  5888.         string $protectedGraphTab = workAreaTab();
  5889.  
  5890.         // Get the name of the hypershade in the protected graph tab so that we
  5891.         // can graph into it.
  5892.         //
  5893.         string $graphUI;
  5894.         string $hypershadeName;
  5895.  
  5896.         $graphUI = lookupComponentName($protectedGraphTab);
  5897.         $hypershadeName = graphUIHypershadeName($graphUI);
  5898.  
  5899.         if (`optionVar -query hsClearBeforeGraphing` == 1)
  5900.         {
  5901.             hyperShade -clearWorkArea $hypershadeName;
  5902.         }
  5903.  
  5904.         hyperShade -shaderNetwork $node $hypershadeName;
  5905.         hyperGraph -edit -frameGraph $hypershadeName;
  5906.  
  5907.         // Select the tab we have just graphed into so the user can see the
  5908.         // graph.
  5909.         //
  5910.         selectTab($panel, $protectedGraphTab);
  5911.     }
  5912. }
  5913.  
  5914. global proc hyperShadePanelSceneAndGraphTabPopupMenu(
  5915.     string $panel,
  5916.     string $hypershade,
  5917.     string $popupMenuName)
  5918. {
  5919.     //
  5920.     // Description:
  5921.     //    This procedure is called when the user RMB clicks in a scene or graph
  5922.     //    tab hypershade editor.
  5923.     //    This procedure builds the menu items which will appear in the popup
  5924.     //    menu.
  5925.     //    If the cursor is over a node, this procedure calls
  5926.     //    sceneAndGraphTabNodePopupMenu() to build the node-specific menu items.
  5927.     //
  5928.  
  5929.     if (!`popupMenu -e -exists $popupMenuName`) return;
  5930.  
  5931.     // Delete the existing menu items from the popup menu.
  5932.     //
  5933.     popupMenu -edit -deleteAllItems $popupMenuName;
  5934.     setParent -menu $popupMenuName;
  5935.  
  5936.     string $node = `hyperGraph -query -feedbackNode $hypershade`;
  5937.     string $gadget = `hyperGraph -query -feedbackGadget $hypershade`;
  5938.  
  5939.     if ($gadget == "Outputs")
  5940.     {
  5941.         hypergraphOutputsMenu($hypershade, $popupMenuName, $node);
  5942.         return;
  5943.     }
  5944.  
  5945.     if ($node != "")
  5946.     {
  5947.         menuItem 
  5948.             -label "Graph Network" 
  5949.             -command 
  5950.                 ("hyperShadePanelGraphNodeNetwork "
  5951.                     + $panel 
  5952.                     + " "
  5953.                     + $hypershade 
  5954.                     + " "
  5955.                     + $node);
  5956.  
  5957.         menuItem -divider true;    
  5958.  
  5959.         buildHypergraphNodePopupMenuItems($hypershade, $node);
  5960.  
  5961.         menuItem -divider true;
  5962.  
  5963.         string $nodeType = `nodeType $node`;
  5964.         menuItem 
  5965.             -label ("Help on \"" + $nodeType + "\"")    
  5966.             -enableCommandRepeat false
  5967.             -command ("showHelp -docs \"Nodes/" + $nodeType + ".html\"");
  5968.     }
  5969.     else
  5970.     {
  5971.         // There is no node under the cursor.
  5972.         //
  5973.         buildMainMenu(
  5974.             $panel, 
  5975.             true); // popup menu
  5976.     }
  5977. }
  5978.  
  5979. global proc hyperShadePanelDiskTabPopupMenu(
  5980.     string $panel,
  5981.     string $editor,
  5982.     string $popupMenu)
  5983. {
  5984.     //
  5985.     // Description:
  5986.     //    This procedure is called when the user RMB clicks in a disk tab visor.
  5987.     //    This procedure builds the menu items which will appear in the popup
  5988.     //    menu.
  5989.     //    The contents of the menu can vary based on the type of file the cursor
  5990.     //    is positioned over.
  5991.     //
  5992.  
  5993.     if (!`popupMenu -e -exists $popupMenu`) return;
  5994.  
  5995.     // Delete the existing menu items from the popup menu.
  5996.     //
  5997.     popupMenu -edit -deleteAllItems $popupMenu;
  5998.     setParent -menu $popupMenu;
  5999.  
  6000.     // Determine what file is under the mouse pointer, if any
  6001.     //
  6002.     string $filePath = `hyperGraph -query -feedbackNode $editor`;
  6003.  
  6004.     if ($filePath != "")
  6005.     {
  6006.         buildHypergraphFilePopupMenuItems($editor, $popupMenu, $filePath);
  6007.     }
  6008.     else
  6009.     {
  6010.         // There is no file under the cursor.
  6011.         //
  6012.         buildMainMenu(
  6013.             $panel, 
  6014.             true); // popup menu
  6015.     }
  6016. }
  6017.  
  6018. proc frame(
  6019.     string $panel,
  6020.     string $frameOperation)
  6021. {
  6022.     //
  6023.     // Description:
  6024.     //    This procedure is called from frameAll() or frameSelected() when
  6025.     //    the user presses a hotkey to frame the contents of a tab in the
  6026.     //    hypershade panel.
  6027.     //    This procedure determines what tab the user's cursor is over, and
  6028.     //    performs a frame all or frame selected operation on the component UI in
  6029.     //    that tab as requested by the $frameOperation.
  6030.     //
  6031.  
  6032.     setParent $panel;
  6033.     string $firstPaneTabs = `setParent firstPaneTabs`;
  6034.     setParent $panel;
  6035.     string $secondPaneTabs = `setParent secondPaneTabs`;
  6036.  
  6037.     string $firstPaneTab = `tabLayout -query -selectTab $firstPaneTabs`;
  6038.     string $secondPaneTab = `tabLayout -query -selectTab $secondPaneTabs`;
  6039.  
  6040.     setParent $firstPaneTabs;
  6041.     $firstPaneTab = `setParent $firstPaneTab`;
  6042.     setParent $secondPaneTabs;
  6043.     $secondPaneTab = `setParent $secondPaneTab`;
  6044.  
  6045.     string $firstPaneHypergraph;
  6046.     string $secondPaneHypergraph;
  6047.  
  6048.     string $componentName;
  6049.  
  6050.     $componentName = lookupComponentName($firstPaneTab);
  6051.  
  6052.     if (isDiskTab($firstPaneTab))
  6053.     {
  6054.         $firstPaneHypergraph = libraryUIFilesVisor($componentName);
  6055.     }
  6056.     else if (isGraphTab($firstPaneTab))
  6057.     {
  6058.         $firstPaneHypergraph = graphUIHypershadeName($componentName);
  6059.     }
  6060.     else if (isSceneTab($firstPaneTab))
  6061.     {
  6062.         $firstPaneHypergraph = collectionUIHypershadeName($componentName);
  6063.     }
  6064.  
  6065.     $componentName = lookupComponentName($secondPaneTab);
  6066.  
  6067.     if (isDiskTab($secondPaneTab))
  6068.     {
  6069.         $secondPaneHypergraph = libraryUIFilesVisor($componentName);
  6070.     }
  6071.     else if (isGraphTab($secondPaneTab))
  6072.     {
  6073.         $secondPaneHypergraph = graphUIHypershadeName($componentName);
  6074.     }
  6075.     else if (isSceneTab($secondPaneTab))
  6076.     {
  6077.         $secondPaneHypergraph = collectionUIHypershadeName($componentName);
  6078.     }
  6079.  
  6080.     if (`hyperGraph -query -isHotkeyTarget $firstPaneHypergraph`)
  6081.     {
  6082.         if ($frameOperation == "all")
  6083.         {
  6084.             hyperGraph
  6085.                 -edit
  6086.                 -frameGraph
  6087.                 $firstPaneHypergraph;
  6088.         }
  6089.         else if ($frameOperation == "selected")
  6090.         {
  6091.             hyperGraph
  6092.                 -edit
  6093.                 -frame
  6094.                 $firstPaneHypergraph;
  6095.         }
  6096.  
  6097.         // Set focus to the tab layout which received the frame command
  6098.         //
  6099.         hyperShadePanelSetActiveTabLayout($panel, "firstPaneTabs");
  6100.     }
  6101.     else if (`hyperGraph -query -isHotkeyTarget $secondPaneHypergraph`)
  6102.     {
  6103.         if ($frameOperation == "all")
  6104.         {
  6105.             hyperGraph
  6106.                 -edit
  6107.                 -frameGraph
  6108.                 $secondPaneHypergraph;
  6109.         }
  6110.         else if ($frameOperation == "selected")
  6111.         {
  6112.             hyperGraph
  6113.                 -edit
  6114.                 -frame
  6115.                 $secondPaneHypergraph;
  6116.         }
  6117.  
  6118.         // Set focus to the tab layout which received the frame command
  6119.         //
  6120.         hyperShadePanelSetActiveTabLayout($panel, "secondPaneTabs");
  6121.     }
  6122. }
  6123.  
  6124. global proc hyperShadePanelFrameAll(
  6125.     string $panel)
  6126. {
  6127.     //
  6128.     // Description:
  6129.     //    This procedure is typically called from fitPanel() in fitPanel.mel when
  6130.     //    the user presses a hotkey to frame the contents of a tab in the
  6131.     //    hypershade panel.
  6132.     //    This procedure calls frame() to perform the operation.
  6133.     //
  6134.     frame($panel, "all");
  6135. }
  6136.  
  6137. global proc hyperShadePanelFrameSelected(
  6138.     string $panel)
  6139. {
  6140.     //
  6141.     // Description:
  6142.     //    This procedure is typically called from fitPanel() in fitPanel.mel when
  6143.     //    the user presses a hotkey to frame the selected items in a tab in the
  6144.     //    hypershade panel.
  6145.     //    This procedure calls frame() to perform the operation.
  6146.     //
  6147.     frame($panel, "selected");
  6148. }
  6149.  
  6150. global proc hyperShadePanelRebuildCreateBarUI(
  6151.     string $panel)
  6152. {
  6153.     //
  6154.     // Description:
  6155.     //    This procedure is called when the contents of the hypershade create bar
  6156.     //    no longer accurately reflect what can be created. Usually this is
  6157.     //    because a plugin has been loaded or unloaded. 
  6158.     //    This procedure deletes the UI in the create bar and rebuilds it.
  6159.     //
  6160.  
  6161.     // Get the name of the layout containing the create bar UI
  6162.     //
  6163.     string $renderCreateBarUI = renderCreateBarUIName($panel);
  6164.  
  6165.     int $managed = renderCreateBarUIIsManaged($renderCreateBarUI); 
  6166.  
  6167.     // Determine the current width of the create bar so that it can
  6168.     // be restored if we decide to collapse it during rebuilding.
  6169.     //
  6170.     int $iconsAndTextWidth = 
  6171.         `optionVar -query hyperShadePanelCreateBarIconsAndTextWidth`;
  6172.  
  6173.     global int $gRenderCreateBarIconsOnlyWidth;
  6174.  
  6175.     int $createBarWidth;
  6176.     string $style = `optionVar -query renderCreateBarStyle`;
  6177.  
  6178.     if ($style == "iconsAndText")
  6179.     {
  6180.         $createBarWidth = $iconsAndTextWidth;
  6181.     }
  6182.     else // ($style == "iconsOnly")
  6183.     {
  6184.         $createBarWidth = $gRenderCreateBarIconsOnlyWidth;
  6185.     }
  6186.  
  6187.     // Hide the section of the hyperShadePanel which contains the
  6188.     // create bar until it has finished building
  6189.     //
  6190.     if ($managed)
  6191.     {
  6192.         // The create bar is currently being displayed.
  6193.         // In order to update it without things looking bad in the process, 
  6194.         // we will collapse the pane which contains the create bar and 
  6195.         // expand it after we are finished.
  6196.         //
  6197.         setParent $panel;
  6198.         formLayout
  6199.             -edit
  6200.             -af paneArrangement    left 1
  6201.             mainForm;
  6202.     }
  6203.  
  6204.     // Delete the existing UI
  6205.     //
  6206.     deleteUI $renderCreateBarUI;
  6207.  
  6208.     // Build the new create bar
  6209.     //
  6210.     string $createBarForm = `setParent createBarForm`;
  6211.     renderCreateBarUI($createBarForm);
  6212.  
  6213.     // Show the create bar again, if it was being shown before
  6214.     //
  6215.     if ($managed)
  6216.     {
  6217.         formLayout
  6218.             -edit
  6219.             -af paneArrangement    left $createBarWidth
  6220.             mainForm;
  6221.     }
  6222. }
  6223.  
  6224. proc pluginChange(
  6225.     string $panel,
  6226.     string $changeType,
  6227.     string $plugin)
  6228. {
  6229.     //
  6230.     // Description:
  6231.     //    This procedure is called from hyperShadePanelLoadPluginCallback() or
  6232.     //    from hyperShadePanelUnloadPluginCallback(). If this method is being
  6233.     //    called because a plugin has been loaded, $changeType should be
  6234.     //    "loadPlugin". If this method is being called because a plugin is
  6235.     //    about to be unloaded, $changeType should be "unloadPlugin". There
  6236.     //    are no other valid values for $changeType.
  6237.     //    This method determines if the create bar UI needs to be updated as a
  6238.     //    result of the loading or unloading of the specified plugin, and if so,
  6239.     //    deletes and rebuilds the create bar UI.
  6240.     //
  6241.  
  6242.     // Get a list of all node types loaded by the plugin
  6243.     //
  6244.     string $pluginNodeTypeArray[] = `pluginInfo -query -dependNode $plugin`;
  6245.  
  6246.     string $nodeType;
  6247.  
  6248.     for ($nodeType in $pluginNodeTypeArray)
  6249.     {
  6250.         // Determine the classification(s) of each node type. Note that nodes
  6251.         // can have multiple classifications.
  6252.         //
  6253.         string $classificationArray[] = `getClassification $nodeType`;
  6254.         string $classification;
  6255.  
  6256.         for ($classification in $classificationArray)
  6257.         {
  6258.             string $tokenArray[];
  6259.             tokenize($classification, "/", $tokenArray);
  6260.  
  6261.             if (    ($tokenArray[0] == "texture")
  6262.                 ||    ($tokenArray[0] == "shader")
  6263.                 ||    ($tokenArray[0] == "light")
  6264.                 ||    ($tokenArray[0] == "utility")
  6265.                 ||    ($tokenArray[0] == "imageplane")
  6266.                 ||    ($tokenArray[0] == "postprocess"))
  6267.             {
  6268.                 // The node type is classified as something which appears
  6269.                 // within the create bar, so we need to refresh
  6270.                 // that window.
  6271.                 //
  6272.                 // Note that the above list needs to be kept in sync with the
  6273.                 // types of nodes which appear in the create bar.
  6274.                 //
  6275.                 if ($changeType == "loadPlugin")
  6276.                 {
  6277.                     hyperShadePanelRebuildCreateBarUI($panel);
  6278.                 }
  6279.                 else if ($changeType == "unloadPlugin")
  6280.                 {
  6281.                     // The plugin is being unloaded, but is not yet gone. We
  6282.                     // want to refresh the create bar but not until
  6283.                     // after the plugin has finished unloading. If we don't
  6284.                     // wait until the plugin has finished unloading, then the
  6285.                     // refreshed create bar will still contain the node types
  6286.                     // defined by the plugin.
  6287.                     // 
  6288.                     // To make sure the plugin has finished unloading before we
  6289.                     // refresh the create bar, we will defer the evaluation of 
  6290.                     // the refresh command until idle time.
  6291.                     //
  6292.                     evalDeferred(
  6293.                         "hyperShadePanelRebuildCreateBarUI " 
  6294.                         + $panel);
  6295.                 }
  6296.             }
  6297.         }
  6298.     }
  6299. }
  6300.  
  6301. global proc hyperShadePanelLoadPluginCallback(
  6302.     string $panel,
  6303.     string $pluginName)
  6304. {
  6305.     //
  6306.     // Description:
  6307.     //    This procedure is called when a plugin has been loaded.
  6308.     //    This procedure calls pluginChange(), which will update the create bar
  6309.     //    if necessary as a result of the newly loaded plugin.
  6310.     //
  6311.  
  6312.     pluginChange($panel, "loadPlugin", $pluginName);
  6313. }
  6314.  
  6315. global proc hyperShadePanelUnloadPluginCallback(
  6316.     string $panel,
  6317.     string $pluginName)
  6318. {
  6319.     //
  6320.     // Description:
  6321.     //    This procedure is called when a plugin is about to be unloaded.
  6322.     //    This procedure calls pluginChange(), which will update the create bar
  6323.     //    if necessary as a result of the unloading of the plugin.
  6324.     //
  6325.     pluginChange($panel, "unloadPlugin", $pluginName);
  6326. }
  6327.  
  6328. global proc hyperShadePanelDecreaseCreateBarSize(
  6329.     string $panel)
  6330. {
  6331.     // 
  6332.     // Description:
  6333.     //    This procedure is called when the user presses the "<<" button shown 
  6334.     //    at the bottom of the create bar when it is in icons and text mode.
  6335.     //    This procedure decreases the width of the create bar and redraws it, 
  6336.     //    unless the new width would be less than a predefined minimum width.
  6337.     //
  6338.     global int $gRenderCreateBarIconsAndTextMinWidth;
  6339.  
  6340.     int $createBarWidth;
  6341.  
  6342.     $createBarWidth = 
  6343.         `optionVar -query hyperShadePanelCreateBarIconsAndTextWidth`;
  6344.     
  6345.     $createBarWidth -= 20;
  6346.  
  6347.     if ($createBarWidth < $gRenderCreateBarIconsAndTextMinWidth)
  6348.     {
  6349.         // The new width would be smaller than the minimum, so we clamp it to
  6350.         // the minimum.
  6351.         //
  6352.         $createBarWidth = $gRenderCreateBarIconsAndTextMinWidth;
  6353.  
  6354.         // Also disable the "<<" button since we aren't going to allow the
  6355.         // create bar to get any narrower than it currently is.
  6356.         //
  6357.         button 
  6358.             -edit
  6359.             -enable false
  6360.             decreaseCreateBarSizeButton;
  6361.     }
  6362.  
  6363.     // Save the new width of the create bar in the option var which represents
  6364.     // it.
  6365.     //
  6366.     optionVar 
  6367.         -intValue hyperShadePanelCreateBarIconsAndTextWidth $createBarWidth;
  6368.     
  6369.     // Adjust the width of the form layout which contains the create bar.
  6370.     //
  6371.     setParent $panel;
  6372.     formLayout
  6373.         -edit
  6374.         -af paneArrangement    left $createBarWidth
  6375.         mainForm;
  6376.  
  6377.     // Ensure the ">>" button is enabled since the create bar is now definitely
  6378.     // narrower than the maximum allowable size.
  6379.     //
  6380.     button 
  6381.         -edit
  6382.         -enable true
  6383.         increaseCreateBarSizeButton;
  6384. }
  6385.  
  6386. global proc hyperShadePanelIncreaseCreateBarSize(
  6387.     string $panel)
  6388. {
  6389.     // 
  6390.     // Description:
  6391.     //    This procedure is called when the user presses the ">>" button shown 
  6392.     //    at the bottom of the create bar when it is in icons and text mode.
  6393.     //    This procedure increases the width of the create bar and redraws it, 
  6394.     //    unless the new width would be greater than a predefined maximum width.
  6395.     //
  6396.  
  6397.     global int $gRenderCreateBarIconsAndTextMaxWidth;
  6398.  
  6399.     int $createBarWidth;
  6400.  
  6401.     $createBarWidth = 
  6402.         `optionVar -query hyperShadePanelCreateBarIconsAndTextWidth`;
  6403.     
  6404.     $createBarWidth += 20;
  6405.  
  6406.     if ($createBarWidth > $gRenderCreateBarIconsAndTextMaxWidth)
  6407.     {
  6408.         // The new width would be larger than the maximum, so we clamp it to
  6409.         // the maximum.
  6410.         //
  6411.         $createBarWidth = $gRenderCreateBarIconsAndTextMaxWidth;
  6412.  
  6413.         // Also disable the ">>" button since we aren't going to allow the
  6414.         // create bar to get any wider than it currently is.
  6415.         //
  6416.         button 
  6417.             -edit
  6418.             -enable false
  6419.             increaseCreateBarSizeButton;
  6420.     }
  6421.  
  6422.     // Save the new width of the create bar in the option var which represents
  6423.     // it.
  6424.     //
  6425.     optionVar 
  6426.         -intValue hyperShadePanelCreateBarIconsAndTextWidth $createBarWidth;
  6427.     
  6428.     // Adjust the width of the form layout which contains the create bar.
  6429.     //
  6430.     setParent $panel;
  6431.     formLayout
  6432.         -edit
  6433.         -af paneArrangement    left $createBarWidth
  6434.         mainForm;
  6435.  
  6436.     // Ensure the "<<" button is enabled since the create bar is now definitely
  6437.     // wider than the minimum allowable size.
  6438.     //
  6439.     button 
  6440.         -edit
  6441.         -enable true
  6442.         decreaseCreateBarSizeButton;
  6443. }
  6444.  
  6445. // ---------------------------------------------------------------------------
  6446. //     Scripted panel support
  6447. // 
  6448.  
  6449. global proc createHyperShadePanel(string $panel) 
  6450. {
  6451.     //
  6452.     // Description:
  6453.     //    This procedure is called the first time the shader editor is opened.
  6454.     //    This procedure creates the various UI entities that the shader
  6455.     //    editor will use, except for those UI entities which are controls.
  6456.     //
  6457. }
  6458.  
  6459.  
  6460. global proc initHyperShadePanel(string $panel)
  6461. {
  6462.     //
  6463.     // This is called when the file changes to make sure that everything
  6464.     // is up-to-date with the new file.  
  6465.     //
  6466. }
  6467.  
  6468. global int $gHypershadePluginCallbacksRegistered = false;
  6469.  
  6470. global proc addHyperShadePanel(string $panel) 
  6471. {
  6472.     //
  6473.     // Description:
  6474.     //    This procedure is called when the hypershade panel is first opened. 
  6475.     //    This procedure creates all of the UI for the hypershade panel.
  6476.     //
  6477.  
  6478.     // Show the wait cursor
  6479.     //
  6480.     waitCursor -state on;
  6481.  
  6482.     // Create the lookup table which will keep track of the tabs, their types,
  6483.     // and their associated components.
  6484.     //
  6485.     createHyperShadePanelLookupTable();
  6486.  
  6487.     buildMainMenu(
  6488.         $panel, 
  6489.         false); // not a popup menu
  6490.  
  6491.     formLayout mainForm;
  6492.         formLayout toolbarForm;
  6493.             int $iconSize = 26;
  6494.             iconTextButton
  6495.                 -image1 "navButtonUnconnected.xpm"
  6496.                 -width $iconSize
  6497.                 -height $iconSize
  6498.                 -annotation "Toggle the Create Bar On/Off"
  6499.                 -command 
  6500.                     ("hyperShadePanelMenuCommand(\"" 
  6501.                         + $panel 
  6502.                         + "\", \"toggleRenderCreateBar\")")
  6503.                 toggleRenderCreateBarButton;
  6504.  
  6505.             separator -horizontal false -style single separator1;
  6506.  
  6507.             iconTextButton
  6508.                 -image1 "hsPrevGraph.xpm"
  6509.                 -width $iconSize
  6510.                 -height $iconSize
  6511.                 -annotation "Show Previous Graph"
  6512.                 -command
  6513.                     ("hyperShadePanelGraphCommand(\""
  6514.                         + $panel
  6515.                         + "\", \"showPreviousGraph\")")
  6516.                 showPreviousGraphButton;
  6517.  
  6518.             iconTextButton
  6519.                 -image1 "hsNextGraph.xpm"
  6520.                 -width $iconSize
  6521.                 -height $iconSize
  6522.                 -annotation "Show Next Graph"
  6523.                 -command
  6524.                     ("hyperShadePanelGraphCommand(\""
  6525.                         + $panel
  6526.                         + "\", \"showNextGraph\")")
  6527.                 showNextGraphButton;
  6528.  
  6529.             separator -horizontal false -style single separator2;
  6530.  
  6531.             iconTextButton
  6532.                 -image1 "hsClearView.xpm"
  6533.                 -width $iconSize
  6534.                 -height $iconSize
  6535.                 -annotation "Clear Graph"
  6536.                 -command 
  6537.                     ("hyperShadePanelGraphCommand(\"" 
  6538.                         + $panel 
  6539.                         + "\", \"clearGraph\")")
  6540.                 clearGraphButton;
  6541.  
  6542.             iconTextButton
  6543.                 -image1 "hsRearrange.xpm"
  6544.                 -width $iconSize
  6545.                 -height $iconSize
  6546.                 -annotation "Rearrange Graph"
  6547.                 -command 
  6548.                     ("hyperShadePanelGraphCommand(\"" 
  6549.                         + $panel 
  6550.                         + "\", \"rearrangeGraph\")")
  6551.                 rearrangeGraphButton;
  6552.  
  6553.             iconTextButton
  6554.                 -image1 "hsGraphMaterial.xpm"
  6555.                 -width $iconSize
  6556.                 -height $iconSize
  6557.                 -annotation "Graph Materials on Selected Objects"
  6558.                 -command 
  6559.                     ("hyperShadePanelGraphCommand(\"" 
  6560.                         + $panel 
  6561.                         + "\", \"graphMaterials\")")
  6562.                 graphMaterialsButton;
  6563.  
  6564.             separator -horizontal false -style single separator3;
  6565.  
  6566.             iconTextButton
  6567.                 -image1 "hsUpStreamCon.xpm"
  6568.                 -width $iconSize
  6569.                 -height $iconSize
  6570.                 -annotation "Input Connections"
  6571.                 -command 
  6572.                     ("hyperShadePanelGraphCommand(\"" 
  6573.                         + $panel 
  6574.                         + "\", \"showUpstream\")")
  6575.                 showUpstreamButton;
  6576.  
  6577.             iconTextButton
  6578.                 -image1 "hsUpDownStreamCon.xpm"
  6579.                 -width $iconSize
  6580.                 -height $iconSize
  6581.                 -annotation "Input and Output Connections"
  6582.                 -command 
  6583.                     ("hyperShadePanelGraphCommand(\"" 
  6584.                         + $panel 
  6585.                         + "\", \"showUpAndDownstream\")")
  6586.                 showUpAndDownstreamButton;
  6587.  
  6588.             iconTextButton
  6589.                 -image1 "hsDownStreamCon.xpm"
  6590.                 -width $iconSize
  6591.                 -height $iconSize
  6592.                 -annotation "Output Connections"
  6593.                 -command 
  6594.                     ("hyperShadePanelGraphCommand(\"" 
  6595.                         + $panel 
  6596.                         + "\", \"showDownstream\")")
  6597.                 showDownstreamButton;
  6598.  
  6599.             iconTextRadioCollection;
  6600.             iconTextRadioButton
  6601.                 -image1 "hsShowTopTabsOnly.xpm"
  6602.                 -width $iconSize
  6603.                 -height $iconSize
  6604.                 -annotation "Show Top Tabs Only"
  6605.                 -onCommand 
  6606.                     ("hyperShadePanelMenuCommand(\"" 
  6607.                         + $panel 
  6608.                         + "\", \"showTopTabsOnly\")")
  6609.                 showTopTabsOnlyButton;
  6610.  
  6611.             iconTextRadioButton
  6612.                 -image1 "hsShowBottomTabsOnly.xpm"
  6613.                 -width $iconSize
  6614.                 -height $iconSize
  6615.                 -annotation "Show Bottom Tabs Only"
  6616.                 -onCommand 
  6617.                     ("hyperShadePanelMenuCommand(\"" 
  6618.                         + $panel 
  6619.                         + "\", \"showBottomTabsOnly\")")
  6620.                 showBottomTabsOnlyButton;
  6621.  
  6622.             iconTextRadioButton
  6623.                 -image1 "hsShowTopAndBottomTabs.xpm"
  6624.                 -width $iconSize
  6625.                 -height $iconSize
  6626.                 -annotation "Show Top and Bottom Tabs"
  6627.                 -onCommand 
  6628.                     ("hyperShadePanelMenuCommand(\"" 
  6629.                         + $panel 
  6630.                         + "\", \"showTopAndBottomTabs\")")
  6631.                 showTopAndBottomTabsButton;
  6632.  
  6633.             formLayout
  6634.                 -edit
  6635.                 -af toggleRenderCreateBarButton top 0 
  6636.                 -af toggleRenderCreateBarButton bottom 0 
  6637.                 -af toggleRenderCreateBarButton left 0
  6638.                 -an toggleRenderCreateBarButton right 
  6639.  
  6640.                 -af separator1 top 0 
  6641.                 -af separator1 bottom 0 
  6642.                 -ac separator1 left 0 toggleRenderCreateBarButton 
  6643.                 -an separator1 right 
  6644.  
  6645.                 -af showPreviousGraphButton top 0 
  6646.                 -af showPreviousGraphButton bottom 0 
  6647.                 -ac showPreviousGraphButton left 0 separator1
  6648.                 -an showPreviousGraphButton right 
  6649.  
  6650.                 -af showNextGraphButton top 0 
  6651.                 -af showNextGraphButton bottom 0 
  6652.                 -ac showNextGraphButton left 0 showPreviousGraphButton
  6653.                 -an showNextGraphButton right 
  6654.  
  6655.                 -af separator2 top 0 
  6656.                 -af separator2 bottom 0 
  6657.                 -ac separator2 left 0 showNextGraphButton 
  6658.                 -an separator2 right 
  6659.  
  6660.                 -af clearGraphButton top 0 
  6661.                 -af clearGraphButton bottom 0 
  6662.                 -ac clearGraphButton left 0 separator2
  6663.                 -an clearGraphButton right 
  6664.  
  6665.                 -af rearrangeGraphButton top 0 
  6666.                 -af rearrangeGraphButton bottom 0 
  6667.                 -ac rearrangeGraphButton left 0 clearGraphButton
  6668.                 -an rearrangeGraphButton right 
  6669.  
  6670.                 -af graphMaterialsButton top 0 
  6671.                 -af graphMaterialsButton bottom 0 
  6672.                 -ac graphMaterialsButton left 0 rearrangeGraphButton
  6673.                 -an graphMaterialsButton right 
  6674.  
  6675.                 -af separator3 top 0 
  6676.                 -af separator3 bottom 0 
  6677.                 -ac separator3 left 0 graphMaterialsButton 
  6678.                 -an separator3 right 
  6679.  
  6680.                 -af showUpstreamButton top 0 
  6681.                 -af showUpstreamButton bottom 0 
  6682.                 -ac showUpstreamButton left 0 separator3
  6683.                 -an showUpstreamButton right 
  6684.  
  6685.                 -af showUpAndDownstreamButton top 0 
  6686.                 -af showUpAndDownstreamButton bottom 0 
  6687.                 -ac showUpAndDownstreamButton left 0 showUpstreamButton
  6688.                 -an showUpAndDownstreamButton right 
  6689.  
  6690.                 -af showDownstreamButton top 0 
  6691.                 -af showDownstreamButton bottom 0 
  6692.                 -ac showDownstreamButton left 0 showUpAndDownstreamButton
  6693.                 -an showDownstreamButton right 
  6694.  
  6695.                 -af showTopAndBottomTabsButton top 0 
  6696.                 -af showTopAndBottomTabsButton bottom 0 
  6697.                 -an showTopAndBottomTabsButton left
  6698.                 -af showTopAndBottomTabsButton right 0
  6699.  
  6700.                 -af showBottomTabsOnlyButton top 0 
  6701.                 -af showBottomTabsOnlyButton bottom 0 
  6702.                 -an showBottomTabsOnlyButton left
  6703.                 -ac showBottomTabsOnlyButton right 0 showTopAndBottomTabsButton 
  6704.  
  6705.                 -af showTopTabsOnlyButton top 0 
  6706.                 -af showTopTabsOnlyButton bottom 0 
  6707.                 -an showTopTabsOnlyButton left
  6708.                 -ac showTopTabsOnlyButton right 0 showBottomTabsOnlyButton 
  6709.  
  6710.                 toolbarForm;
  6711.         setParent ..; // from toolbarForm
  6712.  
  6713.         separator -horizontal true -style single separator3;
  6714.  
  6715.         formLayout createBarWrapForm;
  6716.  
  6717.             string $createBarForm = `formLayout createBarForm`;
  6718.                 string $renderCreateBarUI = renderCreateBarUI($createBarForm);
  6719.                 if (!`optionVar -query hyperShadePanelCreateBarShown`)
  6720.                 {
  6721.                     renderCreateBarUIManage($renderCreateBarUI, false);
  6722.                 }
  6723.             setParent ..; // from $createBarForm
  6724.  
  6725.             // The createBarSizeButtonsFormWrap exists so that the
  6726.             // createBarSizeButtonsForm can be unmanaged/managed in order to 
  6727.             // hide/show the create bar size buttons.
  6728.             //
  6729.             formLayout createBarSizeButtonsFormWrap;
  6730.                 formLayout -numberOfDivisions 2 createBarSizeButtonsForm;
  6731.                 
  6732.                     button
  6733.                         -label "<<"
  6734.                         -height 15
  6735.                         -annotation "Decrease Create Bar size"
  6736.                         -command 
  6737.                             ("hyperShadePanelDecreaseCreateBarSize " + $panel)
  6738.                         decreaseCreateBarSizeButton;
  6739.  
  6740.                     button
  6741.                         -label ">>"
  6742.                         -height 15
  6743.                         -annotation "Increase Create Bar size"
  6744.                         -command 
  6745.                             ("hyperShadePanelIncreaseCreateBarSize " + $panel)
  6746.                         increaseCreateBarSizeButton;
  6747.                     
  6748.                     formLayout
  6749.                         -edit
  6750.  
  6751.                         -af    decreaseCreateBarSizeButton top 0
  6752.                         -af    decreaseCreateBarSizeButton bottom 0
  6753.                         -af    decreaseCreateBarSizeButton left 0
  6754.                         -ap    decreaseCreateBarSizeButton right 0 1
  6755.  
  6756.                         -af    increaseCreateBarSizeButton top 0
  6757.                         -af    increaseCreateBarSizeButton bottom 0
  6758.                         -ap    increaseCreateBarSizeButton left 0 1
  6759.                         -af    increaseCreateBarSizeButton right 0
  6760.  
  6761.                         createBarSizeButtonsForm;
  6762.  
  6763.                 setParent ..; // from createBarSizeButtonsForm
  6764.  
  6765.                 formLayout
  6766.                     -edit
  6767.                     -af createBarSizeButtonsForm top 0
  6768.                     -af createBarSizeButtonsForm bottom 0
  6769.                     -af createBarSizeButtonsForm left 0
  6770.                     -af createBarSizeButtonsForm right 0
  6771.                     createBarSizeButtonsFormWrap;
  6772.  
  6773.             setParent ..; // from createBarSizeButtonsFormWrap
  6774.  
  6775.             formLayout
  6776.                 -edit
  6777.  
  6778.                 -af    createBarForm top 0
  6779.                 -ac    createBarForm bottom 0 createBarSizeButtonsFormWrap
  6780.                 -af    createBarForm left 0
  6781.                 -af    createBarForm right 0
  6782.  
  6783.                 -an    createBarSizeButtonsFormWrap top
  6784.                 -af    createBarSizeButtonsFormWrap bottom 0
  6785.                 -af    createBarSizeButtonsFormWrap left 0
  6786.                 -af    createBarSizeButtonsFormWrap right 0
  6787.  
  6788.                 createBarWrapForm;
  6789.  
  6790.             string $style = `optionVar -query renderCreateBarStyle`;
  6791.  
  6792.             if ($style == "iconsOnly")
  6793.             {
  6794.                 // Unmanage the form layout which contains the resizing
  6795.                 // buttons, since it should not be shown when the create bar is 
  6796.                 // in icons only mode.
  6797.                 //
  6798.                 formLayout
  6799.                     -edit
  6800.                     -manage false
  6801.                     createBarSizeButtonsForm;
  6802.             }
  6803.  
  6804.         setParent ..; // from createBarWrapForm
  6805.  
  6806.         // This variable will define the width of the box around the pane in
  6807.         // hypershade which currently has focus. It needs to be larger on NT
  6808.         // than on IRIX because it is more difficult to see it on NT.
  6809.         //
  6810.         int $activeFrameThickness = 2;
  6811.         string $os = `about -os`;
  6812.  
  6813.         if ($os == "nt")
  6814.         {
  6815.             // Unfortunately, it seems there is a bug in paneLayout on NT as
  6816.             // changing this value does not appear to have any effect.
  6817.             //
  6818.             $activeFrameThickness = 4;
  6819.         }
  6820.  
  6821.         string $paneLayout = 
  6822.             `paneLayout
  6823.                 -configuration "horizontal2" // stacked
  6824.                 -separatorThickness 5
  6825.                 -activeFrameThickness $activeFrameThickness
  6826.                 -activePaneIndex 1
  6827.                 paneArrangement`;
  6828.  
  6829.             tabLayout 
  6830.                 -selectCommand 
  6831.                     ("hyperShadePanelSetActiveTabLayout "
  6832.                         + $panel
  6833.                         + " firstPaneTabs")
  6834.                 firstPaneTabs;
  6835.             setParent ..; // from firstPaneTabs;
  6836.                 
  6837.             tabLayout 
  6838.                 -selectCommand 
  6839.                     ("hyperShadePanelSetActiveTabLayout "
  6840.                         + $panel
  6841.                         + " secondPaneTabs")
  6842.                 secondPaneTabs;
  6843.             setParent ..; // from secondPaneTabs;
  6844.                     
  6845.         setParent ..; // from paneArrangement
  6846.  
  6847.         int $iconsAndTextWidth = 
  6848.             `optionVar -query hyperShadePanelCreateBarIconsAndTextWidth`;
  6849.  
  6850.         global int $gRenderCreateBarIconsOnlyWidth;
  6851.         global int $gRenderCreateBarIconsAndTextMinWidth;
  6852.         global int $gRenderCreateBarIconsAndTextMaxWidth;
  6853.  
  6854.         int $createBarWidth = 1;
  6855.  
  6856.         if (`optionVar -query hyperShadePanelCreateBarShown`)
  6857.         {
  6858.             string $style = `optionVar -query renderCreateBarStyle`;
  6859.  
  6860.             if ($style == "iconsAndText")
  6861.             {
  6862.                 $createBarWidth = $iconsAndTextWidth;
  6863.             }
  6864.             else // ($style == "iconsOnly")
  6865.             {
  6866.                 $createBarWidth = $gRenderCreateBarIconsOnlyWidth;
  6867.             }
  6868.         }
  6869.  
  6870.         if ($createBarWidth == $gRenderCreateBarIconsAndTextMaxWidth)
  6871.         {
  6872.             // Disable the ">>" button since we aren't going to allow the
  6873.             // create bar to get any wider than it currently is.
  6874.             //
  6875.             button 
  6876.                 -edit
  6877.                 -enable false
  6878.                 increaseCreateBarSizeButton;
  6879.         }
  6880.         else if ($createBarWidth == $gRenderCreateBarIconsAndTextMinWidth)
  6881.         {
  6882.             // Disable the "<<" button since we aren't going to allow the
  6883.             // create bar to get any narrower than it currently is.
  6884.             //
  6885.             button 
  6886.                 -edit
  6887.                 -enable false
  6888.                 decreaseCreateBarSizeButton;
  6889.         }
  6890.  
  6891.         formLayout
  6892.             -edit
  6893.  
  6894.             -af toolbarForm top 0
  6895.             -an toolbarForm bottom
  6896.             -af toolbarForm left 0
  6897.             -af toolbarForm right 0
  6898.  
  6899.             -ac separator3    top        0 toolbarForm
  6900.             -an separator3    bottom
  6901.             -af separator3    left    0
  6902.             -af separator3    right    0
  6903.  
  6904.             -ac createBarWrapForm top         1 separator3
  6905.             -af createBarWrapForm bottom     1
  6906.             -af createBarWrapForm left         1
  6907.             -ac createBarWrapForm right     1 paneArrangement
  6908.  
  6909.             -ac paneArrangement    top        1 separator3
  6910.             -af paneArrangement    bottom    1
  6911.             -af paneArrangement    left    $createBarWidth
  6912.             -af paneArrangement    right    1
  6913.  
  6914.             mainForm;
  6915.  
  6916.     setParent ..; // from mainForm
  6917.  
  6918.     optionVar -stringValue "hyperShadePanelWorkAreaTab" "";
  6919.  
  6920.     // Create the tabs
  6921.     //
  6922.     initTabs($panel);
  6923.  
  6924.     // If the user has specified in a previous session that only the top or
  6925.     // bottom tab section is to be displayed, we will continue to do so.
  6926.     //
  6927.     string $tabSectionsShown = 
  6928.         `optionVar -query hyperShadePanelTabSectionsShown`; 
  6929.     
  6930.     if ($tabSectionsShown == "showTopTabsOnly")
  6931.     {
  6932.         showTopTabsOnly($panel);
  6933.     }
  6934.     else if ($tabSectionsShown == "showBottomTabsOnly")
  6935.     {
  6936.         showBottomTabsOnly($panel);
  6937.     }
  6938.  
  6939.     // Refresh the toolbar since it is affected by the currently active tab
  6940.     //
  6941.     refreshToolbar($panel);
  6942.  
  6943.     // Hide the wait cursor
  6944.     //
  6945.     waitCursor -state off;
  6946.  
  6947.     // Establish callbacks which will be called when plugins are
  6948.     // loaded/unloaded. The callbacks will find out what plugin was loaded and 
  6949.     // will update the create bar if necessary.
  6950.     //
  6951.     global int $gHypershadePluginCallbacksRegistered;
  6952.  
  6953.     if (!$gHypershadePluginCallbacksRegistered)
  6954.     {
  6955.         loadPlugin 
  6956.             -addCallback 
  6957.                 ("hyperShadePanelLoadPluginCallback \"" + $panel + "\"") ;
  6958.         unloadPlugin 
  6959.             -addCallback
  6960.                 ("hyperShadePanelUnloadPluginCallback \"" + $panel + "\"") ;
  6961.         $gHypershadePluginCallbacksRegistered = true;
  6962.     }
  6963. }
  6964.  
  6965. proc deleteEditors(
  6966.     string $tabLayout)
  6967. {
  6968.     //
  6969.     // Description:
  6970.     //    This procedure is called from removeHyperShadePanel(). 
  6971.     //    This procedure determines all the hypergraph editors that are being
  6972.     //    used within the specified tab layout and deletes them, since the 
  6973.     //    hypershade is going away.
  6974.     //
  6975.  
  6976.     string $tabArray[] = `tabLayout -query -childArray $tabLayout`;
  6977.     string $tab;
  6978.  
  6979.     // Delete all hypergraph editors being used by this panel
  6980.     //
  6981.     for ($i = 0; $i < size($tabArray); $i++)
  6982.     {
  6983.         $tab = $tabArray[$i];
  6984.         $tab = ($tabLayout + "|" + $tab);
  6985.  
  6986.         string $tabType = lookupTabType($tab);
  6987.         string $component = lookupComponentName($tab);
  6988.         string $hypergraph;
  6989.  
  6990.         if ($tabType == "scene")
  6991.         {
  6992.             string $hypershade = collectionUIHypershadeName($component);
  6993.             hyperGraph -edit -unParent $hypershade;
  6994.             deleteUI $hypershade;
  6995.         }
  6996.         else if ($tabType == "disk")
  6997.         {
  6998.             string $filesVisor = libraryUIFilesVisor($component);
  6999.             string $directoriesVisor = 
  7000.                 libraryUIDirectoriesVisor($component);
  7001.             hyperGraph -edit -unParent $filesVisor;
  7002.             deleteUI $filesVisor;
  7003.             hyperGraph -edit -unParent $directoriesVisor;
  7004.             deleteUI $directoriesVisor;
  7005.         }
  7006.         else if ($tabType == "graph" || $tabType == "protected graph")
  7007.         {
  7008.             string $hypershade = graphUIHypershadeName($component);
  7009.             hyperGraph -edit -unParent $hypershade;
  7010.             deleteUI $hypershade;
  7011.         }
  7012.     }
  7013. }
  7014.  
  7015. global proc removeHyperShadePanel(string $panel) 
  7016. {
  7017.     //
  7018.     // Description:
  7019.     //    This procedure is called when the hypershade is being destroyed
  7020.     //    or reparented. 
  7021.     //    This procedure ensures that all hypergraph/hypershade/visor editors
  7022.     //    used by the various tabs get deleted.
  7023.     //
  7024.  
  7025.     string $tabLayout;
  7026.  
  7027.     setParent $panel;
  7028.     $tabLayout = `setParent firstPaneTabs`;
  7029.     deleteEditors($tabLayout);
  7030.  
  7031.     setParent $panel;
  7032.     $tabLayout = `setParent secondPaneTabs`;
  7033.     deleteEditors($tabLayout);
  7034.  
  7035.     // Unregister the callbacks which are being called when plugins are
  7036.     // loaded/unloaded.
  7037.     //
  7038.     global int $gHypershadePluginCallbacksRegistered;
  7039.  
  7040.     if ($gHypershadePluginCallbacksRegistered)
  7041.     {
  7042.         loadPlugin 
  7043.             -removeCallback 
  7044.                 ("hyperShadePanelLoadPluginCallback \"" + $panel + "\"") ;
  7045.         unloadPlugin 
  7046.             -removeCallback
  7047.                 ("hyperShadePanelUnloadPluginCallback \"" + $panel + "\"") ;
  7048.         $gHypershadePluginCallbacksRegistered = false;
  7049.     }
  7050. }
  7051.  
  7052. global proc string saveStateHyperShadePanel(string $panel) 
  7053. {
  7054.     //
  7055.     // Description:
  7056.     //    This procedure is a required procedure for a scripted panel.
  7057.     //  It is meant to return a string which, when executed, will set the
  7058.     //  panel's state. Because the hypershade panel is far too complicated to
  7059.     //  have its state recorded in a single string, we use other mechanisms to
  7060.     //  remember the state of the hypershade panel. As a result, we will return
  7061.     //  only an empty string from this procedure.
  7062.     //
  7063.  
  7064.     string $stateStr = "";
  7065.     return $stateStr;
  7066. }
  7067.  
  7068. global proc deleteHyperShadePanel(string $panel) 
  7069. {
  7070.     //
  7071.     //  Description:
  7072.     //    Final deletion of the panel.  Clean up any resources that need to be
  7073.     //    freed.
  7074.     //
  7075. }
  7076.  
  7077. global proc hyperShadePanel(string $panel)
  7078. {
  7079.     global string $gMainPane;
  7080.  
  7081.     // Instantiate a new hyperShadePanel
  7082.     //
  7083.     setParent $gMainPane;
  7084.     scriptedPanel -unParent -type hyperShadePanel $panel;
  7085. }
  7086.  
  7087.